forked from oxalica/rust-overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.nix
125 lines (112 loc) · 4.25 KB
/
manifest.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
final: prev:
let
inherit (builtins) match isString toString;
inherit (final.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 = [
"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;
};
# Uncompress the compressed manifest to the original one
# (not complete but has enough information to make up the toolchain).
uncompressManifest = channel: version: {
v, # Rustc version
d, # Date
r, # Renames index
p ? null, # Profiles index
...
}@manifest: rec {
# Version used for derivation.
version = if match ".*(nightly|beta).*" v != null
then "${v}-${d}" # 1.51.0-nightly-2021-01-01, 1.52.0-beta.2-2021-03-27
else v; # 1.51.0
date = d;
renames = mapAttrs (from: to: { inherit to; }) (elemAt renamesList r);
pkg =
mapAttrs (pkgName: { u ? null /* Version appears in URL */, ... }@hashes: {
# 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
target = targets.${targetIdx};
pkgNameStripped = removeSuffix "-preview" pkgName;
targetTail = if targetIdx == "_" then "" else "-" + target;
urlVersion =
if u != null then u # Use specified version for URL if exists.
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".
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}"};
}) (removeAttrs hashes ["u"]);
in
results;
}) (removeAttrs manifest ["v" "d" "r" "p"]);
profiles = if p == null
then {}
else elemAt profilesList p;
targetComponentsList = [
"rust-std"
"rustc-dev"
"rustc-docs"
];
};
uncompressManifestSet = channel: set: let
ret = mapAttrs (uncompressManifest channel) (removeAttrs set ["latest"]);
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);
};
};
}