From 306981fd2a62f07086998024c5d8df199b5b6bba Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 22 Feb 2026 05:28:22 -0500 Subject: [PATCH] fix(rust): use proper `withComponents` toolchain Using this function properly links the `rustup` components together, allowing e.g. `rust-analyzer` to find the location of `rust-src`. --- rust/cargo-nightly/crane+fenix/flake.nix | 4 ++-- rust/cargo-nightly/crane+fenix/shell.nix | 5 +---- rust/cargo-nightly/crane+fenix/toolchain.nix | 13 +++++++++++++ rust/cargo-nightly/nixpkgs+fenix/shell.nix | 5 +---- rust/cargo-nightly/nixpkgs+fenix/toolchain.nix | 13 +++++++++++++ 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 rust/cargo-nightly/crane+fenix/toolchain.nix create mode 100644 rust/cargo-nightly/nixpkgs+fenix/toolchain.nix diff --git a/rust/cargo-nightly/crane+fenix/flake.nix b/rust/cargo-nightly/crane+fenix/flake.nix index 23f75ed..8c66a64 100644 --- a/rust/cargo-nightly/crane+fenix/flake.nix +++ b/rust/cargo-nightly/crane+fenix/flake.nix @@ -16,7 +16,7 @@ packages = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; + toolchain = import ./toolchain.nix fenix.packages.${system} "build"; in { hello = pkgs.callPackage ./package.nix { craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; @@ -33,7 +33,7 @@ checks = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; + toolchain = import ./toolchain.nix fenix.packages.${system} "check"; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; crate = self.packages.${system}.default; in { diff --git a/rust/cargo-nightly/crane+fenix/shell.nix b/rust/cargo-nightly/crane+fenix/shell.nix index 92837d7..9e1ce21 100644 --- a/rust/cargo-nightly/crane+fenix/shell.nix +++ b/rust/cargo-nightly/crane+fenix/shell.nix @@ -1,16 +1,13 @@ { pkgs ? import {}, crane ? builtins.getFlake "github:ipetkov/crane", fenix ? builtins.getFlake "github:nix-community/fenix", - fenixToolchain ? "default" }: let - fenixPkgs = fenix.packages.${pkgs.system}; - toolchain = fenixPkgs.${fenixToolchain}.toolchain; + toolchain = import ./toolchain.nix fenix.packages.${pkgs.stdenv.hostPlatform.system} "dev"; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; in craneLib.devShell { packages = [ toolchain - fenixPkgs.rust-analyzer pkgs.lldb_21 ]; } diff --git a/rust/cargo-nightly/crane+fenix/toolchain.nix b/rust/cargo-nightly/crane+fenix/toolchain.nix new file mode 100644 index 0000000..7a79139 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/toolchain.nix @@ -0,0 +1,13 @@ +fenixPkgs: proc: +fenixPkgs.complete.withComponents ([ + "rustc" + "rust-std" + "cargo" +] ++ (if proc != "build" then [ + "clippy" +] else []) ++ (if proc == "dev" then [ + "rust-docs" + "rustfmt" + "rust-src" + "rust-analyzer" +] else [])) diff --git a/rust/cargo-nightly/nixpkgs+fenix/shell.nix b/rust/cargo-nightly/nixpkgs+fenix/shell.nix index b9167c1..3a56a4f 100644 --- a/rust/cargo-nightly/nixpkgs+fenix/shell.nix +++ b/rust/cargo-nightly/nixpkgs+fenix/shell.nix @@ -1,15 +1,12 @@ { pkgs ? import {}, fenix ? builtins.getFlake "github:nix-community/fenix", - fenixToolchain ? "default" }: let inherit (pkgs) mkShellNoCC; - fenixPkgs = fenix.packages.${pkgs.system}; - toolchain = fenixPkgs.${fenixToolchain}.toolchain; + toolchain = import ./toolchain.nix fenix.packages.${pkgs.stdenv.hostPlatform.system} "dev"; in mkShellNoCC { packages = [ toolchain - fenixPkgs.rust-analyzer pkgs.lldb_21 ]; } diff --git a/rust/cargo-nightly/nixpkgs+fenix/toolchain.nix b/rust/cargo-nightly/nixpkgs+fenix/toolchain.nix new file mode 100644 index 0000000..7a79139 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/toolchain.nix @@ -0,0 +1,13 @@ +fenixPkgs: proc: +fenixPkgs.complete.withComponents ([ + "rustc" + "rust-std" + "cargo" +] ++ (if proc != "build" then [ + "clippy" +] else []) ++ (if proc == "dev" then [ + "rust-docs" + "rustfmt" + "rust-src" + "rust-analyzer" +] else []))