5
5
self : super :
6
6
7
7
let
8
+ inherit ( builtins ) compareVersions fromTOML match readFile tryEval ;
9
+
10
+ inherit ( self . lib )
11
+ any attrNames attrValues concatMapStrings concatStringsSep elem elemAt filter flatten foldl'
12
+ hasPrefix head intersectLists isString length makeLibraryPath makeOverridable mapAttrs
13
+ optional optionalString remove replaceStrings substring subtractLists trace unique ;
8
14
9
15
# FIXME: https://github.com/NixOS/nixpkgs/pull/146274
10
16
toRustTarget = platform :
16
22
# Manifest selector.
17
23
selectManifest = { channel , date ? null } : let
18
24
inherit ( self . rust-bin ) manifests ;
19
- inherit ( builtins ) match elemAt compareVersions attrNames foldl' filter ;
20
- inherit ( self . lib ) hasPrefix ;
21
25
22
26
assertWith = cond : msg : body : if cond then body else throw msg ;
23
27
82
86
if toolchain . _profiles != { } then
83
87
toolchain . _profiles . ${ profile' } or ( throw ''
84
88
Rust ${ toolchain . _version } doesn't have profile `${ profile' } `.
85
- Available profiles are: ${ self . lib . concatStringsSep ", " ( builtins . attrNames toolchain . _profiles ) }
89
+ Available profiles are: ${ concatStringsSep ", " ( attrNames toolchain . _profiles ) }
86
90
'' )
87
91
# Fallback to package `rust` when profiles are not supported and not specified.
88
92
else if profile == null then
96
100
97
101
# Same as `fromRustupToolchain` but read from a `rust-toolchain` file (legacy one-line string or in TOML).
98
102
fromRustupToolchainFile = path : let
99
- inherit ( builtins ) readFile match fromTOML head ;
100
103
content = readFile path ;
101
104
legacy = match "([^\r \n ]+)\r ?\n ?" content ;
102
105
in if legacy != null
@@ -109,26 +112,25 @@ let
109
112
srcInfo = pkg . target . ${ toRustTarget stdenv . targetPlatform } or pkg . target . "*" ;
110
113
components = srcInfo . components or [ ] ;
111
114
componentNamesList =
112
- builtins . map ( pkg : pkg . pkg ) ( builtins . filter ( pkg : ( pkg . target != "*" ) ) components ) ;
115
+ map ( pkg : pkg . pkg ) ( filter ( pkg : ( pkg . target != "*" ) ) components ) ;
113
116
in
114
117
componentNamesList ;
115
118
116
119
getExtensions = pkgs : pkgname : stdenv :
117
120
let
118
- inherit ( super . lib ) unique ;
119
121
pkg = pkgs . ${ pkgname } ;
120
122
rustTarget = toRustTarget stdenv . targetPlatform ;
121
123
srcInfo = pkg . target . ${ rustTarget } or pkg . target . "*" or ( throw "${ pkgname } is no available" ) ;
122
124
extensions = srcInfo . extensions or [ ] ;
123
- extensionNamesList = unique ( builtins . map ( pkg : pkg . pkg ) extensions ) ;
125
+ extensionNamesList = unique ( map ( pkg : pkg . pkg ) extensions ) ;
124
126
in
125
127
extensionNamesList ;
126
128
127
129
hasTarget = pkgs : pkgname : target :
128
130
pkgs ? ${ pkgname } . target . ${ target } ;
129
131
130
132
getTuples = pkgs : name : targets :
131
- builtins . map ( target : { inherit name target ; } ) ( builtins . filter ( target : hasTarget pkgs name target ) targets ) ;
133
+ map ( target : { inherit name target ; } ) ( filter ( target : hasTarget pkgs name target ) targets ) ;
132
134
133
135
# In the manifest, a package might have different components which are bundled with it, as opposed as the extensions which can be added.
134
136
# By default, a package will include the components for the same architecture, and offers them as extensions for other architectures.
@@ -137,12 +139,10 @@ let
137
139
# The list contains the package for the pkgTargets as well as the packages for components for all compTargets
138
140
getTargetPkgTuples = pkgs : pkgname : pkgTargets : compTargets : stdenv :
139
141
let
140
- inherit ( builtins ) elem ;
141
- inherit ( super . lib ) intersectLists ;
142
142
components = getComponentsWithFixedPlatform pkgs pkgname stdenv ;
143
143
extensions = getExtensions pkgs pkgname stdenv ;
144
144
compExtIntersect = intersectLists components extensions ;
145
- tuples = ( getTuples pkgs pkgname pkgTargets ) ++ ( builtins . map ( name : getTuples pkgs name compTargets ) compExtIntersect ) ;
145
+ tuples = ( getTuples pkgs pkgname pkgTargets ) ++ ( map ( name : getTuples pkgs name compTargets ) compExtIntersect ) ;
146
146
in
147
147
tuples ;
148
148
158
158
159
159
mkComponentSrc = { url , sha256 , fetchurl } :
160
160
let
161
- inherit ( builtins ) match elemAt ;
162
- url' = builtins . replaceStrings [ " " ] [ "%20" ] url ; # This is required or download will fail.
161
+ url' = replaceStrings [ " " ] [ "%20" ] url ; # This is required or download will fail.
163
162
# Filter names like `llvm-tools-1.34.2 (6c2484dc3 2019-05-13)-aarch64-unknown-linux-gnu.tar.xz`
164
163
matchParenPart = match ".*/([^ /]*) [(][^)]*[)](.*)" url ;
165
164
name = if matchParenPart == null then "" else ( elemAt matchParenPart 0 ) + ( elemAt matchParenPart 1 ) ;
168
167
169
168
checkMissingExtensions = pkgs : pkgname : stdenv : extensions :
170
169
let
171
- inherit ( builtins ) head ;
172
- inherit ( super . lib ) concatStringsSep subtractLists ;
173
170
availableExtensions = getExtensions pkgs pkgname stdenv ;
174
171
missingExtensions = subtractLists availableExtensions extensions ;
175
172
extensionsToInstall =
182
179
183
180
getComponents = pkgs : pkgname : targets : extensions : targetExtensions : stdenv : fetchurl :
184
181
let
185
- inherit ( builtins ) head map ;
186
- inherit ( super . lib ) flatten remove subtractLists unique ;
187
182
targetExtensionsToInstall = checkMissingExtensions pkgs pkgname stdenv targetExtensions ;
188
183
extensionsToInstall = checkMissingExtensions pkgs pkgname stdenv extensions ;
189
184
hostTargets = [ "*" ( toRustTarget stdenv . hostPlatform ) ( toRustTarget stdenv . targetPlatform ) ] ;
@@ -211,10 +206,10 @@ let
211
206
# Ourselves have offset -1. In order to make these offset -1 dependencies of downstream derivation,
212
207
# they are offset 0 propagated.
213
208
propagatedBuildInputs =
214
- self . lib . optional ( pname == "rustc" ) [ self . stdenv . cc self . buildPackages . stdenv . cc ] ;
209
+ optional ( pname == "rustc" ) [ self . stdenv . cc self . buildPackages . stdenv . cc ] ;
215
210
# This goes downstream packages' buildInputs.
216
211
depsTargetTargetPropagated =
217
- self . lib . optional ( pname == "rustc" && self . stdenv . targetPlatform . isDarwin ) self . libiconv ;
212
+ optional ( pname == "rustc" && self . stdenv . targetPlatform . isDarwin ) self . libiconv ;
218
213
219
214
installPhase = ''
220
215
runHook preInstall
234
229
# This code is inspired by patchelf/setup-hook.sh to iterate over all binaries.
235
230
preFixup =
236
231
let
237
- inherit ( super . lib ) optionalString elem ;
238
232
inherit ( self . stdenv ) hostPlatform ;
239
233
in
240
234
optionalString hostPlatform . isLinux ''
@@ -252,12 +246,12 @@ let
252
246
# Handle executables
253
247
patchelf \
254
248
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
255
- --set-rpath "${ super . lib . makeLibraryPath [ self . zlib ] } :$out/lib" \
249
+ --set-rpath "${ makeLibraryPath [ self . zlib ] } :$out/lib" \
256
250
"$i" || true
257
251
else
258
252
# Handle libraries
259
253
patchelf \
260
- --set-rpath "${ super . lib . makeLibraryPath [ self . zlib ] } :$out/lib" \
254
+ --set-rpath "${ makeLibraryPath [ self . zlib ] } :$out/lib" \
261
255
"$i" || true
262
256
fi
263
257
done < <(find "$dir" -type f -print0)
267
261
for f in $out/bin/*; do
268
262
${ optionalString hostPlatform . isLinux ''
269
263
patchelf \
270
- --set-rpath "${ rustc } /lib:${ super . lib . makeLibraryPath [ self . zlib ] } :$out/lib" \
264
+ --set-rpath "${ rustc } /lib:${ makeLibraryPath [ self . zlib ] } :$out/lib" \
271
265
"$f" || true
272
266
'' }
273
267
${ optionalString hostPlatform . isDarwin ''
304
298
} ;
305
299
306
300
aggregateComponents = { pname , version , components } :
307
- self . pkgs . symlinkJoin {
301
+ self . symlinkJoin {
308
302
name = pname + "-" + version ;
309
303
inherit pname version ;
310
304
325
319
cp -f ${ ./cargo-miri-wrapper.sh } $out/bin/cargo-miri
326
320
chmod +w $out/bin/cargo-miri
327
321
substituteInPlace $out/bin/cargo-miri \
328
- --replace "@bash@" "${ self . pkgs . bash } /bin/bash" \
322
+ --replace "@bash@" "${ self . bash } /bin/bash" \
329
323
--replace "@cargo_miri@" "$out/bin/.cargo-miri-wrapped" \
330
324
--replace "@out@" "$out"
331
325
fi
351
345
, targetExtensions
352
346
} :
353
347
let
354
- inherit ( self . lib ) flatten elem isString filter any remove concatStringsSep concatMapStrings attrNames ;
355
348
rustHostPlatform = toRustTarget self . stdenv . hostPlatform ;
356
349
357
350
collectComponentTargets = allowMissing : compName : comp :
456
449
# *Attention* If you want to install an extension like rust-src, that has no fixed architecture (arch *),
457
450
# you will need to specify this extension in the extensions options or it will not be installed!
458
451
toolchainFromManifest = manifest : let
459
- inherit ( builtins ) elemAt ;
460
- inherit ( super ) makeOverridable ;
461
- inherit ( super . lib ) flip mapAttrs ;
462
-
463
452
maybeRename = name : manifest . renames . ${ name } . to or name ;
464
453
465
454
# For legacy pre-aggregated package `rust`.
517
506
inherit componentSet profileComponents ;
518
507
inherit ( manifest ) targetComponentsList ;
519
508
extensions = extensions ;
520
- targets = self . lib . unique ( [
509
+ targets = unique ( [
521
510
( toRustTarget self . stdenv . hostPlatform ) # Build script requires host std.
522
511
( toRustTarget self . stdenv . targetPlatform )
523
512
] ++ targets ) ;
542
531
# It has more components than `default` profile but less than `complete` profile.
543
532
rust =
544
533
let pkg = mkPackage "rust" manifest . pkg . rust ; in
545
- if builtins . match ".*[.].*[.].*" != null && profiles != { }
546
- then builtins . trace ''
534
+ if match ".*[.].*[.].*" != null && profiles != { }
535
+ then trace ''
547
536
Rust ${ manifest . version } :
548
537
Pre-aggregated package `rust` is not encouraged for stable channel since it contains almost all and uncertain components.
549
538
Consider use `default` profile like `rust-bin.stable.latest.default` and override it with extensions you need.
@@ -558,10 +547,10 @@ let
558
547
} ;
559
548
560
549
# Same as `toolchainFromManifest` but read from a manifest file.
561
- toolchainFromManifestFile = path : toolchainFromManifest ( builtins . fromTOML ( builtins . readFile path ) ) ;
550
+ toolchainFromManifestFile = path : toolchainFromManifest ( fromTOML ( readFile path ) ) ;
562
551
563
552
# Override all pkgs of a toolchain set.
564
- overrideToolchain = attrs : super . lib . mapAttrs ( name : pkg : pkg . override attrs ) ;
553
+ overrideToolchain = attrs : mapAttrs ( name : pkg : pkg . override attrs ) ;
565
554
566
555
# From a git revision of rustc.
567
556
# This does the same thing as crate `rustup-toolchain-install-master`.
576
565
# Rust target to download.
577
566
target ? toRustTarget self . stdenv . targetPlatform
578
567
} : let
579
- shortRev = builtins . substring 0 7 rev ;
580
- components' = super . lib . mapAttrs ( compName : hash : mkComponent {
568
+ shortRev = substring 0 7 rev ;
569
+ components' = mapAttrs ( compName : hash : mkComponent {
581
570
pname = compName ;
582
571
version = shortRev ;
583
572
src = self . fetchurl {
592
581
aggregateComponents {
593
582
inherit pname ;
594
583
version = shortRev ;
595
- components = builtins . attrValues components' ;
584
+ components = attrValues components' ;
596
585
} ;
597
586
598
587
# Select latest nightly toolchain which makes selected profile builds.
601
590
# `selectLatestNightlyWith (toolchain: toolchain.default.override { extensions = "llvm-tools-preview"; })`
602
591
selectLatestNightlyWith = selector :
603
592
let
604
- inherit ( builtins ) attrNames removeAttrs elemAt length trace tryEval ;
605
593
nightlyDates = attrNames ( removeAttrs self . rust-bin . nightly [ "latest" ] ) ;
606
594
dateLength = length nightlyDates ;
607
595
go = idx :
634
622
#
635
623
# For a specific date of nightly:
636
624
# rust-bin.nightly."2020-01-01".default
637
- rust-bin = with builtins ;
625
+ rust-bin =
638
626
( super . rust-bin or { } ) //
639
627
mapAttrs ( channel : mapAttrs ( version : toolchainFromManifest ) ) super . rust-bin . manifests //
640
628
{
657
645
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
658
646
See also README at https://github.com/oxalica/rust-overlay
659
647
'' ;
660
- fromManifestFile = manifestFilePath : { stdenv , fetchurl , patchelf } @deps : builtins . trace ''
648
+ fromManifestFile = manifestFilePath : { stdenv , fetchurl , patchelf } @deps : trace ''
661
649
`fromManifestFile` is deprecated.
662
650
Select a toolchain from `rust-bin` or using `rustChannelOf` instead.
663
651
See also README at https://github.com/oxalica/rust-overlay
0 commit comments