forked from nix-community/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
204 lines (180 loc) · 6.42 KB
/
default.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
let
inherit (builtins)
currentSystem elemAt filter fromJSON mapAttrs match readFile substring;
getFlake = name:
with (fromJSON (readFile ./flake.lock)).nodes.${name}.locked; {
inherit rev;
outPath = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
};
in
{ system ? currentSystem
, pkgs ? import (getFlake "nixpkgs") { localSystem = { inherit system; }; }
, lib ? pkgs.lib
, rust-analyzer-src ? getFlake "rust-analyzer-src"
, rust-analyzer-rev ? substring 0 7 (rust-analyzer-src.rev or "0000000")
}:
let
inherit (lib)
attrVals filterAttrs findFirst foldl importJSON importTOML maintainers
mapAttrs' mapNullable nameValuePair optionalString optionals
pathIsRegularFile unique zipAttrsWith;
v = pkgs.rust.toRustTarget pkgs.stdenv.buildPlatform;
combine' = pkgs.callPackage ./lib/combine.nix { };
mkToolchain = pkgs.callPackage ./lib/mk-toolchain.nix { };
nightlyToolchains = mapAttrs
(_: mapAttrs (profile: mkToolchain "-nightly-${profile}"))
(importJSON ./data/nightly.json);
fromManifest' = target: suffix: manifest:
let
toolchain = mkToolchain suffix {
inherit (manifest) date;
components = mapAttrs
(_: src: { inherit (src) url; sha256 = src.hash; })
(filterAttrs (_: src: src ? available && src.available) (mapAttrs
(_: pkg: pkg.target."*" or pkg.target.${target} or null)
manifest.pkg));
};
in
toolchain // mapAttrs'
(k: v:
nameValuePair "${k}Toolchain" (toolchain.withComponents
(filter (component: toolchain ? ${component}) v)))
manifest.profiles
// {
inherit manifest;
};
fromManifestFile' = target: name: file:
fromManifest' target name (importTOML file);
toolchainOf' = target:
{ root ? "https://static.rust-lang.org/dist"
, channel ? "nightly"
, date ? null
, sha256 ? null
}:
let
url = "${root}${optionalString (date != null) "/${date}"}/channel-rust-${channel}.toml";
in
fromManifestFile' target "-${channel}" (if (sha256 == null) then
builtins.fetchurl url
else
pkgs.fetchurl { inherit url sha256; });
fromToolchainName' = target: name: sha256:
mapNullable
(matches:
let target' = elemAt matches 5; in
toolchainOf' (if target' == null then target else target') {
inherit sha256;
channel = elemAt matches 0;
date = elemAt matches 3;
})
(match
"^(stable|beta|nightly|[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?)(-([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}))?(-([-[:alnum:]]+))?\n?$"
name);
fromToolchainFile' = target:
{ file ? null, dir ? null, sha256 ? null }:
let
text = readFile (if file == null && dir != null then
findFirst pathIsRegularFile
(throw "No rust toolchain file found in ${dir}")
[ (dir + "/rust-toolchain") (dir + "/rust-toolchain.toml") ]
else if file != null && dir == null then
file
else
throw "One and only one of `file` and `dir` should be specified");
toolchain = fromToolchainName' target text sha256;
in
if toolchain == null then
let t = (fromTOML text).toolchain; in
if t ? path then
throw "fenix doesn't support toolchain.path"
else
let toolchain = fromToolchainName' target t.channel sha256; in
combine' "rust-${t.channel}" (attrVals
(filter (component: toolchain ? ${component}) (unique
(toolchain.manifest.profiles.${t.profile or "default"}
++ t.components or [ ])))
toolchain ++ map
(target:
(fromManifest' target "-${t.channel}" toolchain.manifest).rust-std)
(t.targets or [ ]))
else
toolchain.defaultToolchain;
mkToolchains = channel:
let manifest = importJSON (./data + "/${channel}.json"); in
mapAttrs
(target: _: { ${channel} = fromManifest' target "-${channel}" manifest; })
manifest.pkg.rust-std.target;
in
nightlyToolchains.${v} // rec {
combine = combine' "rust-mixed";
fromManifest = fromManifest' v "";
fromManifestFile = fromManifestFile' v "";
toolchainOf = toolchainOf' v;
fromToolchainFile = fromToolchainFile' v;
fromToolchainName = { name, sha256 ? "" }: fromToolchainName' v name sha256;
stable = fromManifest' v "-stable" (importJSON ./data/stable.json);
beta = fromManifest' v "-beta" (importJSON ./data/beta.json);
targets =
let
collectedTargets = zipAttrsWith (_: foldl (x: y: x // y) { }) [
(mkToolchains "stable")
(mkToolchains "beta")
nightlyToolchains
];
in
mapAttrs
(target: v:
v // {
fromManifest = fromManifest' target "";
fromManifestFile = fromManifestFile' target "";
toolchainOf = toolchainOf' target;
fromToolchainFile = fromToolchainFile' target;
})
collectedTargets;
rust-analyzer = (pkgs.makeRustPlatform {
inherit (nightlyToolchains.${v}.minimal) cargo rustc;
}).buildRustPackage {
pname = "rust-analyzer-nightly";
version = rust-analyzer-rev;
src = rust-analyzer-src;
cargoLock.lockFile = rust-analyzer-src + "/Cargo.lock";
cargoBuildFlags = [ "-p" "rust-analyzer" ];
buildInputs = with pkgs;
optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreServices
libiconv
];
doCheck = false;
CARGO_INCREMENTAL = 0;
RUST_ANALYZER_REV = rust-analyzer-rev;
meta = {
maintainers = with maintainers; [ figsoda ];
mainProgram = "rust-analyzer";
};
};
rust-analyzer-vscode-extension =
let
setDefault = k: v: ''
.contributes.configuration.properties."rust-analyzer.${k}".default = "${v}"
'';
in
pkgs.vscode-utils.buildVscodeExtension {
name = "rust-analyzer-${rust-analyzer-rev}";
version = rust-analyzer-rev;
src = ./data/rust-analyzer-vsix.zip;
vscodeExtName = "rust-analyzer";
vscodeExtPublisher = "The Rust Programming Language";
vscodeExtUniqueId = "rust-lang.rust-analyzer";
nativeBuildInputs = with pkgs; [ jq moreutils ];
postPatch = ''
jq -e '
${setDefault "server.path" "${rust-analyzer}/bin/rust-analyzer"}
| ${setDefault "updates.channel" "nightly"}
' package.json | sponge package.json
'';
meta.maintainers = with maintainers; [ figsoda ];
};
}