devshells.nix

 1{ inputs, ... }:
 2{
 3  perSystem =
 4    { pkgs, ... }:
 5    let
 6      # NOTE: Duplicated because this is in a separate flake-parts partition
 7      # than ./packages.nix
 8      mkZed = import ../toolchain.nix { inherit inputs; };
 9      zed-editor = mkZed pkgs;
10
11      rustBin = inputs.rust-overlay.lib.mkRustBin { } pkgs;
12      rustToolchain = rustBin.fromRustupToolchainFile ../../rust-toolchain.toml;
13
14      baseEnv =
15        (zed-editor.overrideAttrs (attrs: {
16          passthru.env = attrs.env;
17        })).env; # exfil `env`; it's not in drvAttrs
18
19      # Musl cross-compiler for building remote_server
20      muslCross = pkgs.pkgsCross.musl64;
21
22      # Cargo build timings wrapper script
23      wrappedCargo = pkgs.writeShellApplication {
24        name = "cargo";
25        runtimeInputs = [ pkgs.nodejs ];
26        text =
27          let
28            pathToCargoScript = ./. + "/../../script/cargo";
29          in
30          ''
31            NIX_WRAPPER=1 CARGO=${rustToolchain}/bin/cargo ${pathToCargoScript} "$@"
32          '';
33      };
34    in
35    {
36      devShells.default = (pkgs.mkShell.override { inherit (zed-editor) stdenv; }) {
37        name = "zed-editor-dev";
38        inputsFrom = [ zed-editor ];
39
40        packages = with pkgs; [
41          wrappedCargo # must be first, to shadow the `cargo` provided by `rustToolchain`
42          rustToolchain # cargo, rustc, and rust-toolchain.toml components included
43          cargo-nextest
44          cargo-hakari
45          cargo-machete
46          cargo-zigbuild
47          # TODO: package protobuf-language-server for editing zed.proto
48          # TODO: add other tools used in our scripts
49
50          # `build.nix` adds this to the `zed-editor` wrapper (see `postFixup`)
51          # we'll just put it on `$PATH`:
52          nodejs_22
53          zig
54        ];
55
56        env =
57          (removeAttrs baseEnv [
58            "LK_CUSTOM_WEBRTC" # download the staticlib during the build as usual
59            "ZED_UPDATE_EXPLANATION" # allow auto-updates
60            "CARGO_PROFILE" # let you specify the profile
61            "TARGET_DIR"
62          ])
63          // {
64            # note: different than `$FONTCONFIG_FILE` in `build.nix` – this refers to relative paths
65            # outside the nix store instead of to `$src`
66            FONTCONFIG_FILE = pkgs.makeFontsConf {
67              fontDirectories = [
68                "./assets/fonts/lilex"
69                "./assets/fonts/ibm-plex-sans"
70              ];
71            };
72            PROTOC = "${pkgs.protobuf}/bin/protoc";
73            ZED_ZSTD_MUSL_LIB = "${pkgs.pkgsCross.musl64.pkgsStatic.zstd.out}/lib";
74            # For aws-lc-sys musl cross-compilation
75            CC_x86_64_unknown_linux_musl = "${muslCross.stdenv.cc}/bin/x86_64-unknown-linux-musl-gcc";
76          };
77      };
78    };
79}