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`.
This commit is contained in:
Kiana Sheibani 2026-02-22 05:28:22 -05:00
parent 5ea809eaa0
commit 306981fd2a
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
5 changed files with 30 additions and 10 deletions

View file

@ -16,7 +16,7 @@
packages = eachSystem (system: packages = eachSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; toolchain = import ./toolchain.nix fenix.packages.${system} "build";
in { in {
hello = pkgs.callPackage ./package.nix { hello = pkgs.callPackage ./package.nix {
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
@ -33,7 +33,7 @@
checks = eachSystem (system: checks = eachSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; toolchain = import ./toolchain.nix fenix.packages.${system} "check";
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
crate = self.packages.${system}.default; crate = self.packages.${system}.default;
in { in {

View file

@ -1,16 +1,13 @@
{ pkgs ? import <nixpkgs> {}, { pkgs ? import <nixpkgs> {},
crane ? builtins.getFlake "github:ipetkov/crane", crane ? builtins.getFlake "github:ipetkov/crane",
fenix ? builtins.getFlake "github:nix-community/fenix", fenix ? builtins.getFlake "github:nix-community/fenix",
fenixToolchain ? "default"
}: }:
let let
fenixPkgs = fenix.packages.${pkgs.system}; toolchain = import ./toolchain.nix fenix.packages.${pkgs.stdenv.hostPlatform.system} "dev";
toolchain = fenixPkgs.${fenixToolchain}.toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
in craneLib.devShell { in craneLib.devShell {
packages = [ packages = [
toolchain toolchain
fenixPkgs.rust-analyzer
pkgs.lldb_21 pkgs.lldb_21
]; ];
} }

View file

@ -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 []))

View file

@ -1,15 +1,12 @@
{ pkgs ? import <nixpkgs> {}, { pkgs ? import <nixpkgs> {},
fenix ? builtins.getFlake "github:nix-community/fenix", fenix ? builtins.getFlake "github:nix-community/fenix",
fenixToolchain ? "default"
}: }:
let let
inherit (pkgs) mkShellNoCC; inherit (pkgs) mkShellNoCC;
fenixPkgs = fenix.packages.${pkgs.system}; toolchain = import ./toolchain.nix fenix.packages.${pkgs.stdenv.hostPlatform.system} "dev";
toolchain = fenixPkgs.${fenixToolchain}.toolchain;
in mkShellNoCC { in mkShellNoCC {
packages = [ packages = [
toolchain toolchain
fenixPkgs.rust-analyzer
pkgs.lldb_21 pkgs.lldb_21
]; ];
} }

View file

@ -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 []))