Add helper `selectLatestNightlyWith`

wip/nixpkgs-raku
oxalica 3 years ago
parent 4fb6f37ee9
commit 55b946ef29
No known key found for this signature in database
GPG Key ID: CED392DE0C483D00
  1. 18
      README.md
  2. 4
      flake.nix
  3. 23
      rust-overlay.nix

@ -137,6 +137,13 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
# Same as `fromRustupToolchain` but read from a `rust-toolchain` file (legacy one-line string or in TOML).
fromRustupToolchainFile = rust-toolchain-file-path: «derivation»;
# Select the latest nightly toolchain which have specific components or profile available.
# This helps nightly users in case of latest nightly may not contains all components they want.
#
# `selectLatestNightlyWith (toolchain: toolchain.default)` selects the latest nightly toolchain
# with all `default` components (rustc, cargo, rustfmt, ...) available.
selectLatestNightlyWith = selector: «derivation»;
# [Experimental]
# Custom toolchain from a specific rustc git revision.
# This does almost the same thing as `rustup-toolchain-install-master`. (https://crates.io/crates/rustup-toolchain-install-master)
@ -179,6 +186,9 @@ Running `nix develop` will create a shell with the default nightly Rust toolchai
nightly = {
# The latest nightly toolchain.
# It is preferred to use `selectLatestNightlyWith` instead of this since
# nightly toolchain may have components (like `rustfmt` or `rls`) missing,
# making `default` profile unusable.
latest = { /* toolchain */ };
"2020-12-31" = { /* toolchain */ };
"2020-12-30" = { /* toolchain */ };
@ -224,6 +234,14 @@ Some examples (assume `nixpkgs` had the overlay applied):
}
```
- Select the latest nightly toolchain with default components and `llvm-tools-preview` all available.
It may select toolchain earlier than `rust-bin.nightly.latest` due to lack of components.
```nix
rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "llvm-tools-preview" ];
})
```
- If you already have a [`rust-toolchain` file for rustup][rust-toolchain],
you can simply use `fromRustupToolchainFile` to get the customized toolchain derivation.

@ -164,7 +164,9 @@
});
};
checkDrvs = {};
checkDrvs = lib.optionalAttrs (lib.elem system [ "aarch64-linux" "x86_64-linux" ]) {
latest-nightly-default = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
};
failedAssertions =
lib.filter (msg: msg != null) (

@ -535,6 +535,28 @@ let
components = builtins.attrValues components';
};
# Select latest nightly toolchain which makes selected profile builds.
# Some components are missing in some nightly releases.
# Usage:
# `selectLatestNightlyWith (toolchain: toolchain.default.override { extensions = "llvm-tools-preview"; })`
selectLatestNightlyWith = selector:
let
inherit (builtins) attrNames removeAttrs elemAt length trace tryEval;
nightlyDates = attrNames (removeAttrs self.rust-bin.nightly [ "latest" ]);
dateLength = length nightlyDates;
go = idx:
let ret = selector (self.rust-bin.nightly.${elemAt nightlyDates idx}); in
if idx == 0 then
ret
else if dateLength - idx >= 256 then
trace "Failed to select nightly version after 100 tries" ret
else if ret != null && (tryEval ret.drvPath).success then
ret
else
go (idx - 1);
in
go (length nightlyDates - 1);
in {
# For each channel:
# rust-bin.stable.latest.cargo
@ -558,6 +580,7 @@ in {
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) super.rust-bin.manifests //
{
inherit fromRustupToolchain fromRustupToolchainFile;
inherit selectLatestNightlyWith;
# Experimental feature.
inherit fromRustcRev;
};

Loading…
Cancel
Save