flake.nix

 1{
 2  description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
 3
 4  inputs = {
 5    nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
 6    rust-overlay = {
 7      url = "github:oxalica/rust-overlay";
 8      inputs.nixpkgs.follows = "nixpkgs";
 9    };
10    crane.url = "github:ipetkov/crane";
11    flake-compat.url = "github:edolstra/flake-compat";
12  };
13
14  outputs =
15    {
16      nixpkgs,
17      rust-overlay,
18      crane,
19      ...
20    }:
21    let
22      systems = [
23        "x86_64-linux"
24        "x86_64-darwin"
25        "aarch64-linux"
26        "aarch64-darwin"
27      ];
28
29      overlays = {
30        rust-overlay = rust-overlay.overlays.default;
31        rust-toolchain = final: prev: {
32          rustToolchain = final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
33        };
34        zed-editor = final: prev: {
35          zed-editor = final.callPackage ./nix/build.nix {
36            crane = crane.mkLib final;
37            rustToolchain = final.rustToolchain;
38          };
39        };
40      };
41
42      mkPkgs =
43        system:
44        import nixpkgs {
45          inherit system;
46          overlays = builtins.attrValues overlays;
47        };
48
49      forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (mkPkgs system));
50    in
51    {
52      packages = forAllSystems (pkgs: {
53        default = pkgs.zed-editor;
54      });
55
56      devShells = forAllSystems (pkgs: {
57        default = pkgs.callPackage ./nix/shell.nix { };
58      });
59
60      formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
61
62      overlays = overlays // {
63        default = nixpkgs.lib.composeManyExtensions (builtins.attrValues overlays);
64      };
65    };
66
67  nixConfig = {
68    extra-substituters = [
69      "https://zed-industries.cachix.org"
70    ];
71    extra-trusted-public-keys = [
72      "zed-industries.cachix.org-1:QW3RoXK0Lm4ycmU5/3bmYRd3MLf4RbTGPqRulGlX5W0="
73    ];
74  };
75}