Skip to content

Commit b454a69

Browse files
committed
rust: replaces fenix with rust-overlay now allows specifying version
1 parent a8495ab commit b454a69

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/modules/languages/rust.nix

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
let
44
cfg = config.languages.rust;
55

6-
fenix = config.lib.getInput {
7-
name = "fenix";
8-
url = "github:nix-community/fenix";
9-
attribute = "languages.rust.version";
6+
rust-overlay = config.lib.getInput {
7+
name = "rust-overlay";
8+
url = "github:oxalica/rust-overlay";
9+
attribute = "languages.rust.input";
1010
follows = [ "nixpkgs" ];
1111
};
1212
in
1313
{
1414
imports = [
15-
(lib.mkRenamedOptionModule [ "languages" "rust" "version" ] [ "languages" "rust" "channel" ])
1615
(lib.mkRenamedOptionModule [ "languages" "rust" "packages" ] [ "languages" "rust" "toolchain" ])
1716
];
1817

@@ -34,7 +33,7 @@ in
3433
default = [ ];
3534
defaultText = lib.literalExpression ''[ ]'';
3635
description = ''
37-
List of extra [targets](https://github.com/nix-community/fenix#supported-platforms-and-targets)
36+
List of extra [targets](https://doc.rust-lang.org/nightly/rustc/platform-support.html)
3837
to install. Defaults to only the native target.
3938
'';
4039
};
@@ -46,6 +45,16 @@ in
4645
description = "The rustup toolchain to install.";
4746
};
4847

48+
version = lib.mkOption {
49+
type = lib.types.str;
50+
default = "latest";
51+
defaultText = lib.literalExpression ''"latest"'';
52+
description = ''
53+
Which version of rust to use, this value could be `latest`,`1.81.0`, `2021-01-01`.
54+
Only works when languages.rust.channel is NOT nixpkgs.
55+
'';
56+
};
57+
4958
rustflags = lib.mkOption {
5059
type = lib.types.str;
5160
default = "";
@@ -101,6 +110,17 @@ in
101110
The nixpkgs channel does not support cross-compiling with targets.
102111
Use the stable, beta, or nightly channels instead. For example:
103112
113+
languages.rust.channel = "stable";
114+
'';
115+
}
116+
{
117+
assertion = cfg.channel == "nixpkgs" -> (cfg.version == "latest");
118+
message = ''
119+
Cannot use `languages.rust.channel = "nixpkgs"` with `languages.rust.version`.
120+
121+
The nixpkgs channel does not contain all versions required, and is
122+
therefore not supported to be used together.
123+
104124
languages.rust.channel = "stable";
105125
'';
106126
}
@@ -153,23 +173,15 @@ in
153173

154174
(lib.mkIf (cfg.channel != "nixpkgs") (
155175
let
156-
rustPackages = fenix.packages.${pkgs.stdenv.system};
157-
fenixChannel =
158-
if cfg.channel == "nightly"
159-
then "latest"
160-
else cfg.channel;
161-
toolchain = rustPackages.${fenixChannel};
176+
toolchain = (rust-overlay.lib.mkRustBin {} pkgs)."${cfg.channel}"."${cfg.version}";
177+
# filter toolchain, otherwise it contains a bunch of non-rust stuff (llvm-tools, etc.)
178+
filteredToolchain = (lib.filterAttrs (n: _: builtins.elem n toolchain._manifest.profiles.complete) toolchain);
162179
in
163180
{
164181
languages.rust.toolchain =
165-
(builtins.mapAttrs (_: pkgs.lib.mkDefault) toolchain);
182+
(builtins.mapAttrs (_: pkgs.lib.mkDefault) filteredToolchain);
166183

167-
packages = [
168-
(rustPackages.combine (
169-
(map (c: toolchain.${c}) cfg.components) ++
170-
(map (t: rustPackages.targets.${t}.${fenixChannel}.rust-std) cfg.targets)
171-
))
172-
];
184+
packages = builtins.attrValues (lib.filterAttrs (n: _: builtins.elem n cfg.components) cfg.toolchain);
173185
}
174186
))
175187
]);

0 commit comments

Comments
 (0)