Skip to content

Commit

Permalink
Add support for legacy rust-toolchain
Browse files Browse the repository at this point in the history
Change to immutable URLs
  • Loading branch information
oxalica committed Jan 3, 2021
1 parent 10d1db9 commit 926e333
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ Here's an example of using it in nixos configuration.
distRoot = "https://static.rust-lang.org/dist";
# Select a toolchain and aggregate components by rustup's `rust-toolchain` file format.
# See: https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
# See: https://github.com/ebroto/rustup/blob/c2db7dac6b38c99538eec472db9d23d18f918409/README.md#the-toolchain-file
fromRustupToolchain = { channel, components ? [], targets ? [] }: «derivation»;
# Same as `fromRustupToolchain` but read from a `rust-toolchain` TOML file.
# Same as `fromRustupToolchain` but read from a `rust-toolchain` file (legacy one-line string or in TOML).
fromRustupToolchainFile = rust-toolchain-file-path: «derivation»;
stable = {
Expand Down
8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@
extensions = [ "rustfmt-preview" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
rustup-toolchain-customization-file = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain)

rustup-toolchain-file-toml = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain-toml)
(nightly."2020-07-10".rust.override {
extensions = [ "rustfmt-preview" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
rustup-toolchain-file-legacy = assertEq
(fromRustupToolchainFile ./tests/rust-toolchain-legacy)
nightly."2020-07-10".rust;
};

checkDrvs = {};
Expand Down
14 changes: 11 additions & 3 deletions rust-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ let
else throw "Unknown channel: ${channel}";

# Select a toolchain and aggregate components by rustup's `rust-toolchain` file format.
# See: https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
# See: https://github.com/ebroto/rustup/blob/c2db7dac6b38c99538eec472db9d23d18f918409/README.md#the-toolchain-file
fromRustupToolchain = { channel, components ? [], targets ? [] }:
(toolchainFromManifest (selectManifest { inherit channel; })).rust.override {
extensions = components;
inherit targets;
};

# Same as `fromRustupToolchain` but read from a `rust-toolchain` file (legacy one-line string or in TOML).
fromRustupToolchainFile = path: let
inherit (builtins) readFile match fromTOML head;
content = readFile path;
legacy = match "([^\r\n]+)\r?\n?" content;
in if legacy != null
then fromRustupToolchain { channel = head legacy; }
else fromRustupToolchain (fromTOML content).toolchain;

getComponentsWithFixedPlatform = pkgs: pkgname: stdenv:
let
pkg = pkgs.${pkgname};
Expand Down Expand Up @@ -315,8 +324,7 @@ in {
(super.rust-bin or {}) //
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) super.rust-bin.manifests //
{
fromRustupToolchainFile = path: fromRustupToolchain (fromTOML (readFile path)).toolchain;
inherit fromRustupToolchain;
inherit fromRustupToolchain fromRustupToolchainFile;
};

# All attributes below are for compatiblity with mozilla overlay.
Expand Down
1 change: 1 addition & 0 deletions tests/rust-toolchain-legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2020-07-10
File renamed without changes.

0 comments on commit 926e333

Please sign in to comment.