Add `fromRustcRev` for rust component development

wip/nixpkgs-raku
oxalica 3 years ago
parent 11fe19255b
commit 038f0fb575
No known key found for this signature in database
GPG Key ID: CED392DE0C483D00
  1. 19
      README.md
  2. 96
      rust-overlay.nix

@ -92,6 +92,12 @@ Here's an example of using it in nixos configuration.
# Same as `fromRustupToolchain` but read from a `rust-toolchain` file (legacy one-line string or in TOML).
fromRustupToolchainFile = rust-toolchain-file-path: «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)
# Parameter `components` should be an attrset with component name as key and its SRI hash as value.
fromRustcRev = { pname ? .., rev, components, target ? .. }: «derivation»;
stable = {
# The latest stable toolchain.
latest = {
@ -163,6 +169,19 @@ Some examples (assume `nixpkgs` had the overlay applied):
```nix
nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain
```
- *\[Experimental\]*
Toolchain with specific rustc git revision.
This is useful for development of rust components like [MIRI](https://github.com/rust-lang/miri).
Note: the example below may not built since upstream CI periodly removes old artifacts.
```nix
rust-bin.fromRustcRev {
rev = "a2cd91ceb0f156cb442d75e12dc77c3d064cdde4";
components = {
rustc = "sha256-x+OkPVStX00AiC3GupIdGzWluIK1BnI4ZCBbg72+ZuI=";
rust-src = "sha256-13PpzzYtd769Xkb0QzHpNfYCOnLMWFolc9QyYq98z2k=";
};
}
```
For more details, see also the source code of `./rust-overlay.nix`.

@ -149,11 +149,8 @@ let
in
map (tuple: { name = tuple.name; src = (getFetchUrl pkgs tuple.name tuple.target stdenv fetchurl); }) pkgsTuplesToInstall;
installComponents = stdenv: namesAndSrcs:
let
inherit (builtins) map;
installComponent = name: src:
stdenv.mkDerivation {
self.stdenv.mkDerivation {
inherit name;
inherit src;
@ -239,8 +236,35 @@ let
dontStrip = true;
};
in
map (nameAndSrc: (installComponent nameAndSrc.name nameAndSrc.src)) namesAndSrcs;
aggregateComponents = { pname, version, namesAndSrcs }:
self.pkgs.symlinkJoin {
name = pname + "-" + version;
inherit pname version;
paths = builtins.map ({ name, src }: (installComponent name src)) namesAndSrcs;
postBuild = ''
# If rustc or rustdoc is in the derivation, we need to copy their
# executable into the final derivation. This is required
# for making them find the correct SYSROOT.
for target in $out/bin/{rustc,rustdoc}; do
if [ -e $target ]; then
cp --remove-destination "$(realpath -e $target)" $target
fi
done
'';
# Add the compiler as part of the propagated build inputs in order
# to run:
#
# $ nix-shell -p rustChannels.stable.rust
#
# And get a fully working Rust compiler, with the stdenv linker.
propagatedBuildInputs = [ self.stdenv.cc ];
meta.platforms = self.lib.platforms.all;
};
# Genereate the toolchain set from a parsed manifest.
#
@ -290,35 +314,10 @@ let
extensions' = map maybeRename extensions;
targetExtensions' = map maybeRename targetExtensions;
namesAndSrcs = getComponents pkgs.pkg name targets extensions' targetExtensions' stdenv fetchurl;
components = installComponents stdenv namesAndSrcs;
componentsOuts = builtins.map (comp: (super.lib.strings.escapeNixString (super.lib.getOutput "out" comp))) components;
in
super.pkgs.symlinkJoin {
name = name + "-" + version;
aggregateComponents {
pname = name;
inherit version;
paths = components;
postBuild = ''
# If rustc or rustdoc is in the derivation, we need to copy their
# executable into the final derivation. This is required
# for making them find the correct SYSROOT.
for target in $out/bin/{rustc,rustdoc}; do
if [ -e $target ]; then
cp --remove-destination "$(realpath -e $target)" $target
fi
done
'';
# Add the compiler as part of the propagated build inputs in order
# to run:
#
# $ nix-shell -p rustChannels.stable.rust
#
# And get a fully working Rust compiler, with the stdenv linker.
propagatedBuildInputs = [ stdenv.cc ];
meta.platforms = stdenv.lib.platforms.all;
inherit version namesAndSrcs;
}
) {
extensions = [];
@ -339,6 +338,35 @@ let
# Override all pkgs of a toolchain set.
overrideToolchain = attrs: super.lib.mapAttrs (name: pkg: pkg.override attrs);
# From a git revision of rustc.
# This does the same thing as crate `rustup-toolchain-install-master`.
# But you need to manually provide component hashes.
fromRustcRev = {
# Package name of the derivation.
pname ? "rust-custom",
# Git revision of rustc.
rev,
# Attrset with component name as key and its SRI hash as value.
components,
# Rust target to download.
target ? super.rust.toRustTarget self.stdenv.targetPlatform
}: let
shortRev = builtins.substring 0 7 rev;
namesAndSrcs = super.lib.mapAttrsToList (component: hash: {
name = "${component}-${shortRev}";
src = self.fetchurl {
url = if component == "rust-src"
then "https://ci-artifacts.rust-lang.org/rustc-builds/${rev}/${component}-nightly.tar.xz"
else "https://ci-artifacts.rust-lang.org/rustc-builds/${rev}/${component}-nightly-${target}.tar.xz";
inherit hash;
};
}) components;
in
aggregateComponents {
version = shortRev;
inherit pname namesAndSrcs;
};
in {
# For each channel:
# rust-bin.stable.latest.cargo
@ -362,6 +390,8 @@ in {
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) super.rust-bin.manifests //
{
inherit fromRustupToolchain fromRustupToolchainFile;
# Experimental feature.
inherit fromRustcRev;
};
# All attributes below are for compatiblity with mozilla overlay.

Loading…
Cancel
Save