Files
rust-overlay/manifest.nix

126 lines
4.2 KiB
Nix
Raw Normal View History

final: prev:
2021-01-01 10:21:00 +08:00
let
inherit (builtins) match isString toString;
inherit (final.lib)
attrNames concatMap elemAt filter hasAttr mapAttrs mapAttrs' removeSuffix;
2021-01-01 10:21:00 +08:00
targets = import ./manifests/targets.nix // { _ = "*"; };
2021-01-04 02:20:36 +08:00
renamesList = import ./manifests/renames.nix;
2021-04-04 01:17:15 +08:00
profilesList = import ./manifests/profiles.nix;
2021-01-01 10:21:00 +08:00
inherit (final.rust-bin) distRoot;
2021-01-01 10:21:00 +08:00
# Extensions for mixed `rust` pkg.
components = [
"rustc"
"rust-std"
"cargo"
];
singleTargetExtensions = [
"clippy-preview"
"miri-preview"
"rls-preview"
"rust-analyzer-preview"
"rustfmt-preview"
"llvm-tools-preview"
"rust-analysis"
];
multiTargetExtensions = [
"rust-std"
"rustc-dev"
"rustc-docs"
"rust-src" # This has only one special target `*`
];
rustPkgExtra = pkgs: target: let
singleTargetTups = map
(pkg: { inherit pkg target; })
(filter (p: hasAttr p pkgs && hasAttr target pkgs.${p}.target) singleTargetExtensions);
multiTargetTups = concatMap
(pkg: map (target: { inherit pkg target; }) (attrNames pkgs.${pkg}.target))
(filter (p: hasAttr p pkgs) multiTargetExtensions);
in {
components = map (pkg: { inherit pkg target; }) components;
extensions = singleTargetTups ++ multiTargetTups;
};
2021-01-04 02:20:36 +08:00
# Uncompress the compressed manifest to the original one
# (not complete but has enough information to make up the toolchain).
2021-01-05 03:38:46 -06:00
uncompressManifest = channel: version: {
2021-04-04 01:17:15 +08:00
v, # Rustc version
d, # Date
r, # Renames index
p ? null, # Profiles index
2021-01-04 03:11:32 +08:00
...
}@manifest: rec {
2021-04-04 01:17:15 +08:00
# Version used for derivation.
version = if match ".*(nightly|beta).*" v != null
2021-04-04 01:17:15 +08:00
then "${v}-${d}" # 1.51.0-nightly-2021-01-01, 1.52.0-beta.2-2021-03-27
else v; # 1.51.0
2021-01-04 02:23:56 +08:00
date = d;
2021-01-04 02:20:36 +08:00
renames = mapAttrs (from: to: { inherit to; }) (elemAt renamesList r);
2021-04-04 01:17:15 +08:00
2021-01-01 10:21:00 +08:00
pkg =
2021-04-04 01:17:15 +08:00
mapAttrs (pkgName: { u ? null /* Version appears in URL */, ... }@hashes: {
2021-01-04 03:11:32 +08:00
# We use rustc version for all components to reduce manifest size.
# This version is just used for component derivation name.
version = "${v} (000000000 ${d})"; # "<version> (<commit-hash> yyyy-mm-dd)"
target = let
results = mapAttrs' (targetIdx: hash: let
2021-01-01 10:21:00 +08:00
target = targets.${targetIdx};
2021-01-01 22:42:15 +08:00
pkgNameStripped = removeSuffix "-preview" pkgName;
2021-01-01 10:21:00 +08:00
targetTail = if targetIdx == "_" then "" else "-" + target;
2021-01-01 22:42:15 +08:00
urlVersion =
2021-04-04 01:17:15 +08:00
if u != null then u # Use specified version for URL if exists.
2021-01-05 03:38:46 -06:00
else if channel == "stable" then v # For stable channel, default to be rustc version.
else channel; # Otherwise, for beta/nightly channel, default to be "beta"/"nightly".
2021-01-01 10:21:00 +08:00
in {
name = target;
value =
# Normally, hash is just the hash.
if isString hash then
{
xz_url = "${distRoot}/${date}/${pkgNameStripped}-${urlVersion}${targetTail}.tar.xz";
xz_hash = hash;
} // (if pkgName == "rust" then rustPkgExtra pkg target else {})
# But hash can be an integer to forward to another URL.
# This occurs in aarch64-apple-darwin rust-docs on 2022-02-02.
else
results.${targets."_${toString hash}"};
2021-01-04 03:11:32 +08:00
}) (removeAttrs hashes ["u"]);
in
results;
2021-04-04 01:17:15 +08:00
}) (removeAttrs manifest ["v" "d" "r" "p"]);
profiles = if p == null
then {}
else elemAt profilesList p;
2021-04-04 01:17:15 +08:00
targetComponentsList = [
"rust-std"
"rustc-dev"
"rustc-docs"
];
2021-01-01 10:21:00 +08:00
};
2021-01-05 03:38:46 -06:00
uncompressManifestSet = channel: set: let
ret = mapAttrs (uncompressManifest channel) (removeAttrs set ["latest"]);
2021-01-01 10:21:00 +08:00
in ret // { latest = ret.${set.latest}; };
2021-01-02 20:42:57 +08:00
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);
};
};
2021-01-02 20:42:57 +08:00
}