Skip to content

Commit

Permalink
feat(rust): Parameterize the toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
akirak committed Nov 25, 2024
1 parent d864f0e commit 0dde100
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions rust/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

outputs =
inputs@{ nixpkgs, flake-parts, ... }:
let
# For details on these options, See
# https://github.com/oxalica/rust-overlay?tab=readme-ov-file#cheat-sheet-common-usage-of-rust-bin
#
# Channel of the Rust toolchain (stable or beta).
rustChannel = "stable";
# Version (latest or specific date/semantic version)
rustVersion = "latest";
# Profile (default or minimal)
rustProfile = "default";
in
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;

Expand All @@ -40,7 +51,9 @@
inherit system;
overlays = [ inputs.rust-overlay.overlays.default ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (pkgs: pkgs.rust-bin.stable.latest.default);
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
pkgs: pkgs.rust-bin.${rustChannel}.${rustVersion}.${rustProfile}
);
commonArgs = {
# Depending on your code base, you may have to customize the
# source filtering to include non-standard files during the build.
Expand Down Expand Up @@ -72,7 +85,9 @@
++ (commonArgs.buildInputs or [ ])
++ [ pkgs.rust-analyzer-unwrapped ];

RUST_SRC_PATH = "${pkgs.rust-bin.stable.latest.rust-src}/lib/rustlib/src/rust/library";
RUST_SRC_PATH = "${
pkgs.rust-bin.${rustChannel}.${rustVersion}.rust-src
}/lib/rustlib/src/rust/library";
};

treefmt = {
Expand Down

0 comments on commit 0dde100

Please sign in to comment.