|
3 | 3 | let
|
4 | 4 | cfg = config.languages.rust;
|
5 | 5 |
|
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"; |
10 | 10 | follows = [ "nixpkgs" ];
|
11 | 11 | };
|
12 | 12 | in
|
13 | 13 | {
|
14 | 14 | imports = [
|
15 |
| - (lib.mkRenamedOptionModule [ "languages" "rust" "version" ] [ "languages" "rust" "channel" ]) |
16 | 15 | (lib.mkRenamedOptionModule [ "languages" "rust" "packages" ] [ "languages" "rust" "toolchain" ])
|
17 | 16 | ];
|
18 | 17 |
|
|
34 | 33 | default = [ ];
|
35 | 34 | defaultText = lib.literalExpression ''[ ]'';
|
36 | 35 | 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) |
38 | 37 | to install. Defaults to only the native target.
|
39 | 38 | '';
|
40 | 39 | };
|
|
46 | 45 | description = "The rustup toolchain to install.";
|
47 | 46 | };
|
48 | 47 |
|
| 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 | + |
49 | 58 | rustflags = lib.mkOption {
|
50 | 59 | type = lib.types.str;
|
51 | 60 | default = "";
|
|
101 | 110 | The nixpkgs channel does not support cross-compiling with targets.
|
102 | 111 | Use the stable, beta, or nightly channels instead. For example:
|
103 | 112 |
|
| 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 | +
|
104 | 124 | languages.rust.channel = "stable";
|
105 | 125 | '';
|
106 | 126 | }
|
|
153 | 173 |
|
154 | 174 | (lib.mkIf (cfg.channel != "nixpkgs") (
|
155 | 175 | 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); |
162 | 179 | in
|
163 | 180 | {
|
164 | 181 | languages.rust.toolchain =
|
165 |
| - (builtins.mapAttrs (_: pkgs.lib.mkDefault) toolchain); |
| 182 | + (builtins.mapAttrs (_: pkgs.lib.mkDefault) filteredToolchain); |
166 | 183 |
|
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); |
173 | 185 | }
|
174 | 186 | ))
|
175 | 187 | ]);
|
|
0 commit comments