mirror of
https://github.com/oxalica/rust-overlay.git
synced 2025-10-06 00:02:40 +02:00
*: refactor and bubble up self-dependencies from final
/self
Clean up entangled self-references and make inputs explicit through arguments.
This commit is contained in:
72
default.nix
72
default.nix
@@ -1,2 +1,72 @@
|
||||
# Overlay interface for non-flake Nix.
|
||||
final: prev:
|
||||
(import ./lib/rust-bin.nix final) (prev // (import ./lib/manifests.nix final prev))
|
||||
let
|
||||
inherit (builtins) mapAttrs readFile;
|
||||
|
||||
inherit (final) lib rust-bin;
|
||||
inherit (rust-bin._internal) toolchainFromManifest selectManifest;
|
||||
|
||||
# Same as `toolchainFromManifest` but read from a manifest file.
|
||||
toolchainFromManifestFile = path: toolchainFromManifest (fromTOML (readFile path));
|
||||
|
||||
# Override all pkgs of a toolchain set.
|
||||
overrideToolchain = attrs: mapAttrs (name: pkg: pkg.override attrs);
|
||||
|
||||
# This is eagerly evaluated and disallow overriding. Get this from `final`
|
||||
# will easily encounter infinite recursion without manually expand all attrs
|
||||
# from `rust-bin.nix` output like `mkIf` does.
|
||||
# This is considered internal anyway.
|
||||
manifests = import ./lib/manifests.nix {
|
||||
inherit lib;
|
||||
inherit (rust-bin) distRoot;
|
||||
};
|
||||
|
||||
in {
|
||||
rust-bin = (prev.rust-bin or { }) // {
|
||||
# The overridable dist url for fetching.
|
||||
distRoot = "https://static.rust-lang.org/dist";
|
||||
} // import ./lib/rust-bin.nix {
|
||||
inherit lib manifests;
|
||||
inherit (final.rust) toRustTarget;
|
||||
inherit (rust-bin) nightly;
|
||||
pkgs = final;
|
||||
};
|
||||
|
||||
# All attributes below are for compatibility with mozilla overlay.
|
||||
|
||||
lib = (prev.lib or { }) // {
|
||||
rustLib = (prev.lib.rustLib or { }) // {
|
||||
manifest_v2_url = throw ''
|
||||
`manifest_v2_url` is not supported.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'';
|
||||
fromManifest = throw ''
|
||||
`fromManifest` is not supported due to network access during evaluation.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'';
|
||||
fromManifestFile = manifestFilePath: { stdenv, fetchurl, patchelf }@deps: builtins.trace ''
|
||||
`fromManifestFile` is deprecated.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'' (overrideToolchain deps (toolchainFromManifestFile manifestFilePath));
|
||||
};
|
||||
};
|
||||
|
||||
rustChannelOf = manifestArgs: toolchainFromManifest (selectManifest manifestArgs);
|
||||
|
||||
latest = (prev.latest or {}) // {
|
||||
rustChannels = {
|
||||
stable = rust-bin.stable.latest;
|
||||
beta = rust-bin.beta.latest;
|
||||
nightly = rust-bin.nightly.latest;
|
||||
};
|
||||
};
|
||||
|
||||
rustChannelOfTargets = channel: date: targets:
|
||||
(final.rustChannelOf { inherit channel date; })
|
||||
.rust.override { inherit targets; };
|
||||
|
||||
rustChannels = final.latest.rustChannels;
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
final: prev:
|
||||
# Manifests which describe the content of each version.
|
||||
{ lib, distRoot }:
|
||||
let
|
||||
inherit (builtins) match isString toString;
|
||||
|
||||
inherit (final.lib)
|
||||
inherit (lib)
|
||||
attrNames concatMap elemAt filter hasAttr mapAttrs mapAttrs' removeSuffix;
|
||||
|
||||
targets = import ../manifests/targets.nix // { _ = "*"; };
|
||||
renamesList = import ../manifests/renames.nix;
|
||||
profilesList = import ../manifests/profiles.nix;
|
||||
|
||||
inherit (final.rust-bin) distRoot;
|
||||
|
||||
# Extensions for mixed `rust` pkg.
|
||||
components = [
|
||||
@@ -110,16 +110,7 @@ let
|
||||
in ret // { latest = ret.${set.latest}; };
|
||||
|
||||
in {
|
||||
rust-bin = (prev.rust-bin or {}) // {
|
||||
# The dist url for fetching.
|
||||
# Override it if you want to use a mirror server.
|
||||
distRoot = "https://static.rust-lang.org/dist";
|
||||
|
||||
# For internal usage.
|
||||
manifests = {
|
||||
stable = uncompressManifestSet "stable" (import ../manifests/stable);
|
||||
beta = uncompressManifestSet "beta" (import ../manifests/beta);
|
||||
nightly = uncompressManifestSet "nightly" (import ../manifests/nightly);
|
||||
};
|
||||
};
|
||||
stable = uncompressManifestSet "stable" (import ../manifests/stable);
|
||||
beta = uncompressManifestSet "beta" (import ../manifests/beta);
|
||||
nightly = uncompressManifestSet "nightly" (import ../manifests/nightly);
|
||||
}
|
||||
|
135
lib/rust-bin.nix
135
lib/rust-bin.nix
@@ -1,14 +1,22 @@
|
||||
# Define component resolution and utility functions.
|
||||
self: super:
|
||||
|
||||
# Component resolution, aggregation and other utility functions.
|
||||
# Provide the content of `rust-bin`.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
toRustTarget,
|
||||
manifests,
|
||||
nightly,
|
||||
}:
|
||||
let
|
||||
inherit (builtins) compareVersions fromTOML match readFile tryEval;
|
||||
|
||||
inherit (self.lib)
|
||||
inherit (lib)
|
||||
any attrNames attrValues concatStringsSep elem elemAt filter flatten foldl'
|
||||
hasPrefix head isString length listToAttrs makeOverridable mapAttrs
|
||||
mapAttrsToList optional optionalAttrs replaceStrings substring trace unique;
|
||||
|
||||
inherit (pkgs) stdenv callPackage fetchurl;
|
||||
|
||||
# Remove keys from attrsets whose value is null.
|
||||
removeNulls = set:
|
||||
removeAttrs set
|
||||
@@ -16,27 +24,26 @@ let
|
||||
(attrNames set));
|
||||
|
||||
# FIXME: https://github.com/NixOS/nixpkgs/pull/146274
|
||||
toRustTarget = platform:
|
||||
toRustTarget' = platform:
|
||||
if platform.isWasi then
|
||||
"${platform.parsed.cpu.name}-wasi"
|
||||
else
|
||||
platform.rust.rustcTarget or (super.rust.toRustTarget platform);
|
||||
platform.rust.rustcTarget or (toRustTarget platform);
|
||||
|
||||
# The platform where `rustc` is running.
|
||||
rustHostPlatform = toRustTarget self.stdenv.hostPlatform;
|
||||
rustHostPlatform = toRustTarget' stdenv.hostPlatform;
|
||||
# The platform of binary which `rustc` produces.
|
||||
rustTargetPlatform = toRustTarget self.stdenv.targetPlatform;
|
||||
rustTargetPlatform = toRustTarget' stdenv.targetPlatform;
|
||||
|
||||
mkComponentSet = self.callPackage ./mk-component-set.nix {
|
||||
inherit toRustTarget removeNulls;
|
||||
mkComponentSet = callPackage ./mk-component-set.nix {
|
||||
inherit removeNulls;
|
||||
toRustTarget = toRustTarget';
|
||||
};
|
||||
|
||||
mkAggregated = self.callPackage ./mk-aggregated.nix {};
|
||||
mkAggregated = callPackage ./mk-aggregated.nix {};
|
||||
|
||||
# Manifest selector.
|
||||
selectManifest = { channel, date ? null }: let
|
||||
inherit (self.rust-bin) manifests;
|
||||
|
||||
assertWith = cond: msg: body: if cond then body else throw msg;
|
||||
|
||||
# https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification
|
||||
@@ -127,7 +134,7 @@ let
|
||||
matchParenPart = match ".*/([^ /]*) [(][^)]*[)](.*)" url;
|
||||
name = if matchParenPart == null then "" else (elemAt matchParenPart 0) + (elemAt matchParenPart 1);
|
||||
in
|
||||
self.fetchurl { inherit name sha256; url = url'; };
|
||||
fetchurl { inherit name sha256; url = url'; };
|
||||
|
||||
# Resolve final components to install from mozilla-overlay style `extensions`, `targets` and `targetExtensions`.
|
||||
#
|
||||
@@ -252,8 +259,6 @@ let
|
||||
# *Attention* If you want to install an extension like rust-src, that has no fixed architecture (arch *),
|
||||
# you will need to specify this extension in the extensions options or it will not be installed!
|
||||
toolchainFromManifest = manifest: let
|
||||
maybeRename = name: manifest.renames.${name}.to or name;
|
||||
|
||||
# platform -> true
|
||||
# For fail-fast test.
|
||||
allPlatformSet =
|
||||
@@ -348,12 +353,6 @@ let
|
||||
_manifest = manifest;
|
||||
};
|
||||
|
||||
# Same as `toolchainFromManifest` but read from a manifest file.
|
||||
toolchainFromManifestFile = path: toolchainFromManifest (fromTOML (readFile path));
|
||||
|
||||
# Override all pkgs of a toolchain set.
|
||||
overrideToolchain = attrs: 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.
|
||||
@@ -370,7 +369,7 @@ let
|
||||
target ? rustTargetPlatform
|
||||
}: let
|
||||
hashToSrc = compName: hash:
|
||||
self.fetchurl {
|
||||
fetchurl {
|
||||
url = if compName == "rust-src"
|
||||
then "https://ci-artifacts.rust-lang.org/rustc-builds/${rev}/${compName}-nightly.tar.xz"
|
||||
else "https://ci-artifacts.rust-lang.org/rustc-builds/${rev}/${compName}-nightly-${target}.tar.xz";
|
||||
@@ -394,10 +393,10 @@ let
|
||||
# `selectLatestNightlyWith (toolchain: toolchain.default.override { extensions = ["llvm-tools-preview"]; })`
|
||||
selectLatestNightlyWith = selector:
|
||||
let
|
||||
nightlyDates = attrNames (removeAttrs self.rust-bin.nightly [ "latest" ]);
|
||||
nightlyDates = attrNames (removeAttrs nightly [ "latest" ]);
|
||||
dateLength = length nightlyDates;
|
||||
go = idx:
|
||||
let ret = selector (self.rust-bin.nightly.${elemAt nightlyDates idx}); in
|
||||
let ret = selector (nightly.${elemAt nightlyDates idx}); in
|
||||
if idx == 0 then
|
||||
ret
|
||||
else if dateLength - idx >= 256 then
|
||||
@@ -409,67 +408,31 @@ let
|
||||
in
|
||||
go (length nightlyDates - 1);
|
||||
|
||||
in {
|
||||
# For each channel:
|
||||
# rust-bin.stable.latest.{minimal,default,complete} # Profiles.
|
||||
# rust-bin.stable.latest.rust # Pre-aggregate from upstream.
|
||||
# rust-bin.stable.latest.cargo # Components...
|
||||
# rust-bin.stable.latest.rustc
|
||||
# rust-bin.stable.latest.rust-docs
|
||||
# ...
|
||||
#
|
||||
# For a specific version of stable:
|
||||
# rust-bin.stable."1.47.0".default
|
||||
#
|
||||
# For a specific date of beta:
|
||||
# rust-bin.beta."2021-01-01".default
|
||||
#
|
||||
# For a specific date of nightly:
|
||||
# rust-bin.nightly."2020-01-01".default
|
||||
rust-bin =
|
||||
(super.rust-bin or {}) //
|
||||
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) super.rust-bin.manifests //
|
||||
{
|
||||
inherit fromRustupToolchain fromRustupToolchainFile;
|
||||
inherit selectLatestNightlyWith;
|
||||
inherit fromRustcRev;
|
||||
};
|
||||
in
|
||||
# For each channel:
|
||||
# rust-bin.stable.latest.{minimal,default,complete} # Profiles.
|
||||
# rust-bin.stable.latest.rust # Pre-aggregate from upstream.
|
||||
# rust-bin.stable.latest.cargo # Components...
|
||||
# rust-bin.stable.latest.rustc
|
||||
# rust-bin.stable.latest.rust-docs
|
||||
# ...
|
||||
#
|
||||
# For a specific version of stable:
|
||||
# rust-bin.stable."1.47.0".default
|
||||
#
|
||||
# For a specific date of beta:
|
||||
# rust-bin.beta."2021-01-01".default
|
||||
#
|
||||
# For a specific date of nightly:
|
||||
# rust-bin.nightly."2020-01-01".default
|
||||
mapAttrs (channel: mapAttrs (version: toolchainFromManifest)) manifests //
|
||||
{
|
||||
inherit fromRustupToolchain fromRustupToolchainFile;
|
||||
inherit selectLatestNightlyWith;
|
||||
inherit fromRustcRev;
|
||||
|
||||
# All attributes below are for compatiblity with mozilla overlay.
|
||||
|
||||
lib = (super.lib or {}) // {
|
||||
rustLib = (super.lib.rustLib or {}) // {
|
||||
manifest_v2_url = throw ''
|
||||
`manifest_v2_url` is not supported.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'';
|
||||
fromManifest = throw ''
|
||||
`fromManifest` is not supported due to network access during evaluation.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'';
|
||||
fromManifestFile = manifestFilePath: { stdenv, fetchurl, patchelf }@deps: trace ''
|
||||
`fromManifestFile` is deprecated.
|
||||
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
|
||||
See also README at https://github.com/oxalica/rust-overlay
|
||||
'' (overrideToolchain deps (toolchainFromManifestFile manifestFilePath));
|
||||
};
|
||||
_internal = {
|
||||
inherit toolchainFromManifest;
|
||||
inherit selectManifest;
|
||||
};
|
||||
|
||||
rustChannelOf = manifestArgs: toolchainFromManifest (selectManifest manifestArgs);
|
||||
|
||||
latest = (super.latest or {}) // {
|
||||
rustChannels = {
|
||||
stable = self.rust-bin.stable.latest;
|
||||
beta = self.rust-bin.beta.latest;
|
||||
nightly = self.rust-bin.nightly.latest;
|
||||
};
|
||||
};
|
||||
|
||||
rustChannelOfTargets = channel: date: targets:
|
||||
(self.rustChannelOf { inherit channel date; })
|
||||
.rust.override { inherit targets; };
|
||||
|
||||
rustChannels = self.latest.rustChannels;
|
||||
}
|
||||
|
Reference in New Issue
Block a user