Use fenix toolchain in nix shell (#18227)

In #17974 we explicitly depend on rustc/cargo for the nix devShell,
however the fenix overlay that contains the latest stable versions was
not being applied to that shell. This led to the shell inheriting
whatever rustc/cargo was on nixos-unstable from nixpkgs, which sometimes
lags behind. This change fixes that, and also restructures the flake to
ensure that all outputs rely on the overlaid `pkgs`.

Release Notes:

- N/A
This commit is contained in:
jvmncs 2024-09-23 10:16:15 -04:00 committed by GitHub
parent d784e72027
commit 2ff8dde925
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 38 deletions

18
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1725409566, "lastModified": 1727060013,
"narHash": "sha256-PrtLmqhM6UtJP7v7IGyzjBFhbG4eOAHT6LPYOFmYfbk=", "narHash": "sha256-/fC5YlJy4IoAW9GhkJiwyzk0K/gQd9Qi4rRcoweyG9E=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "7e4586bad4e3f8f97a9271def747cf58c4b68f3c", "rev": "6b40cc876c929bfe1e3a24bf538ce3b5622646ba",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -23,11 +23,11 @@
"rust-analyzer-src": "rust-analyzer-src" "rust-analyzer-src": "rust-analyzer-src"
}, },
"locked": { "locked": {
"lastModified": 1726813972, "lastModified": 1727073227,
"narHash": "sha256-t6turZgoSAVgj7hn5mxzNlLOeVeZvymFo8+ymB52q34=", "narHash": "sha256-1kmkEQmFfGVuPBasqSZrNThqyMDV1SzTalQdRZxtDRs=",
"owner": "nix-community", "owner": "nix-community",
"repo": "fenix", "repo": "fenix",
"rev": "251caeafc75b710282ee7e375800f75f4c8c5727", "rev": "88cc292eb3c689073c784d6aecc0edbd47e12881",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -53,11 +53,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1726642912, "lastModified": 1726937504,
"narHash": "sha256-wiZzKGHRAhItEuoE599Wm3ic+Lg/NykuBvhb+awf7N8=", "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "395c52d142ec1df377acd67db6d4a22950b02a98", "rev": "9357f4f23713673f310988025d9dc261c20e70c6",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -17,27 +17,34 @@
fenix, fenix,
... ...
}: let }: let
forAllSystems = function: systems = ["x86_64-linux" "aarch64-linux"];
nixpkgs.lib.genAttrs [
"x86_64-linux" overlays = {
"aarch64-linux" fenix = fenix.overlays.default;
] (system: rust-toolchain = final: prev: {
function (import nixpkgs { rustToolchain = final.fenix.stable.toolchain;
inherit system; };
overlays = [fenix.overlays.default]; zed-editor = final: prev: {
})); zed-editor = final.callPackage ./nix/build.nix {
craneLib = (crane.mkLib final).overrideToolchain final.rustToolchain;
rustPlatform = final.makeRustPlatform {
inherit (final.rustToolchain) cargo rustc;
};
};
};
};
mkPkgs = system:
import nixpkgs {
inherit system;
overlays = builtins.attrValues overlays;
};
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (mkPkgs system));
in { in {
packages = forAllSystems (pkgs: let packages = forAllSystems (pkgs: {
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.fenix.stable.toolchain); zed-editor = pkgs.zed-editor;
rustPlatform = pkgs.makeRustPlatform { default = pkgs.zed-editor;
inherit (pkgs.fenix.stable.toolchain) cargo rustc;
};
nightlyBuild = pkgs.callPackage ./nix/build.nix {
inherit craneLib rustPlatform;
};
in {
zed-editor = nightlyBuild;
default = nightlyBuild;
}); });
devShells = forAllSystems (pkgs: { devShells = forAllSystems (pkgs: {
@ -46,13 +53,10 @@
formatter = forAllSystems (pkgs: pkgs.alejandra); formatter = forAllSystems (pkgs: pkgs.alejandra);
overlays.default = final: prev: { overlays =
zed-editor = final.callPackage ./nix/build.nix { overlays
craneLib = (crane.mkLib final).overrideToolchain (p: p.fenix.stable.toolchain); // {
rustPlatform = final.makeRustPlatform { default = nixpkgs.lib.composeManyExtensions (builtins.attrValues overlays);
inherit (final.fenix.stable.toolchain) cargo rustc;
};
}; };
};
}; };
} }

View file

@ -20,8 +20,7 @@ in
wayland wayland
xorg.libxcb xorg.libxcb
vulkan-loader vulkan-loader
rustc rustToolchain
cargo
]; ];
in in
pkgs.mkShell.override {inherit stdenv;} { pkgs.mkShell.override {inherit stdenv;} {