templates/rust/cargo-nightly/crane+fenix/flake.nix
Kiana Sheibani 306981fd2a
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`.
2026-02-22 05:28:22 -05:00

59 lines
1.8 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, systems, crane, fenix, ... }:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
fenixToolchain = "default";
in {
packages = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = import ./toolchain.nix fenix.packages.${system} "build";
in {
hello = pkgs.callPackage ./package.nix {
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
};
default = self.packages.${system}.hello;
});
devShells = eachSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./shell.nix { inherit pkgs crane fenix fenixToolchain; };
});
checks = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = import ./toolchain.nix fenix.packages.${system} "check";
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
crate = self.packages.${system}.default;
in {
inherit crate;
clippy = craneLib.cargoClippy (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
crate.commonArgs
// {
inherit (crate) cargoArtifacts;
env.RUSTDOCFLAGS = "--deny warnings";
}
);
});
};
}