diff --git a/README.md b/README.md index 6e2ada95893..fbfcab72288 100644 --- a/README.md +++ b/README.md @@ -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 = { diff --git a/flake.nix b/flake.nix index 53562958cce..685b6e10abc 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = {}; diff --git a/rust-overlay.nix b/rust-overlay.nix index 737b9e7681f..2943532c786 100644 --- a/rust-overlay.nix +++ b/rust-overlay.nix @@ -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}; @@ -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. diff --git a/tests/rust-toolchain-legacy b/tests/rust-toolchain-legacy new file mode 100644 index 00000000000..95a7229aa56 --- /dev/null +++ b/tests/rust-toolchain-legacy @@ -0,0 +1 @@ +nightly-2020-07-10 diff --git a/tests/rust-toolchain b/tests/rust-toolchain-toml similarity index 100% rename from tests/rust-toolchain rename to tests/rust-toolchain-toml