|
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 | + |
| 13 | + # https://github.com/nix-community/fenix/blob/cdfd7bf3e3edaf9e3f6d1e397d3ee601e513613c/lib/combine.nix |
| 14 | + combine = name: paths: |
| 15 | + pkgs.symlinkJoin { |
| 16 | + inherit name paths; |
| 17 | + postBuild = '' |
| 18 | + for file in $(find $out/bin -xtype f -maxdepth 1); do |
| 19 | + install -m755 $(realpath "$file") $out/bin |
| 20 | + |
| 21 | + if [[ $file =~ /rustfmt$ ]]; then |
| 22 | + continue |
| 23 | + fi |
| 24 | + |
| 25 | + ${lib.optionalString pkgs.stdenv.isLinux '' |
| 26 | + if isELF "$file"; then |
| 27 | + patchelf --set-rpath $out/lib "$file" || true |
| 28 | + fi |
| 29 | + ''} |
| 30 | + |
| 31 | + ${lib.optionalString pkgs.stdenv.isDarwin '' |
| 32 | + install_name_tool -add_rpath $out/lib "$file" || true |
| 33 | + ''} |
| 34 | + done |
| 35 | + |
| 36 | + for file in $(find $out/lib -name "librustc_driver-*"); do |
| 37 | + install $(realpath "$file") "$file" |
| 38 | + done |
| 39 | + ''; |
| 40 | + }; |
12 | 41 | in
|
13 | 42 | {
|
14 | 43 | imports = [
|
15 |
| - (lib.mkRenamedOptionModule [ "languages" "rust" "version" ] [ "languages" "rust" "channel" ]) |
16 | 44 | (lib.mkRenamedOptionModule [ "languages" "rust" "packages" ] [ "languages" "rust" "toolchain" ])
|
17 | 45 | ];
|
18 | 46 |
|
|
34 | 62 | default = [ ];
|
35 | 63 | defaultText = lib.literalExpression ''[ ]'';
|
36 | 64 | description = ''
|
37 |
| - List of extra [targets](https://github.com/nix-community/fenix#supported-platforms-and-targets) |
38 |
| - to install. Defaults to only the native target. |
| 65 | + List of extra [targets](https://doc.rust-lang.org/nightly/rustc/platform-support.html) |
| 66 | + to install. Defaults to only the native target. |
39 | 67 | '';
|
40 | 68 | };
|
41 | 69 |
|
|
46 | 74 | description = "The rustup toolchain to install.";
|
47 | 75 | };
|
48 | 76 |
|
| 77 | + version = lib.mkOption { |
| 78 | + type = lib.types.str; |
| 79 | + default = "latest"; |
| 80 | + defaultText = lib.literalExpression ''"latest"''; |
| 81 | + description = '' |
| 82 | + Which version of rust to use, this value could be `latest`,`1.81.0`, `2021-01-01`. |
| 83 | + Only works when languages.rust.channel is NOT nixpkgs. |
| 84 | + ''; |
| 85 | + }; |
| 86 | + |
49 | 87 | rustflags = lib.mkOption {
|
50 | 88 | type = lib.types.str;
|
51 | 89 | default = "";
|
|
101 | 139 | The nixpkgs channel does not support cross-compiling with targets.
|
102 | 140 | Use the stable, beta, or nightly channels instead. For example:
|
103 | 141 |
|
| 142 | + languages.rust.channel = "stable"; |
| 143 | + ''; |
| 144 | + } |
| 145 | + { |
| 146 | + assertion = cfg.channel == "nixpkgs" -> (cfg.version == "latest"); |
| 147 | + message = '' |
| 148 | + Cannot use `languages.rust.channel = "nixpkgs"` with `languages.rust.version`. |
| 149 | +
|
| 150 | + The nixpkgs channel does not contain all versions required, and is |
| 151 | + therefore not supported to be used together. |
| 152 | +
|
104 | 153 | languages.rust.channel = "stable";
|
105 | 154 | '';
|
106 | 155 | }
|
|
154 | 203 |
|
155 | 204 | (lib.mkIf (cfg.channel != "nixpkgs") (
|
156 | 205 | let
|
157 |
| - rustPackages = fenix.packages.${pkgs.stdenv.system}; |
158 |
| - fenixChannel = |
159 |
| - if cfg.channel == "nightly" |
160 |
| - then "latest" |
161 |
| - else cfg.channel; |
162 |
| - toolchain = rustPackages.${fenixChannel}; |
| 206 | + toolchain = (rust-overlay.lib.mkRustBin { } pkgs.buildPackages)."${cfg.channel}"."${cfg.version}"; |
| 207 | + filteredToolchain = (lib.filterAttrs (n: _: builtins.elem n toolchain._manifest.profiles.complete) toolchain); |
163 | 208 | in
|
164 | 209 | {
|
165 | 210 | languages.rust.toolchain =
|
166 |
| - (builtins.mapAttrs (_: pkgs.lib.mkDefault) toolchain); |
| 211 | + (builtins.mapAttrs (_: pkgs.lib.mkDefault) filteredToolchain); |
167 | 212 |
|
168 | 213 | packages = [
|
169 |
| - (rustPackages.combine ( |
170 |
| - (map (c: toolchain.${c}) cfg.components) ++ |
171 |
| - (map (t: rustPackages.targets.${t}.${fenixChannel}.rust-std) cfg.targets) |
| 214 | + (combine "rust-mixed" ( |
| 215 | + (map (c: cfg.toolchain.${c}) (cfg.components ++ [ "rust-std" ])) ++ |
| 216 | + (map (t: toolchain._components.${t}.rust-std) cfg.targets) |
172 | 217 | ))
|
173 | 218 | ];
|
174 | 219 | }
|
|
0 commit comments