Skip to content

Commit 1438622

Browse files
pkgs/top-level/stage.nix: move most nixpkgs sets to variants
1 parent db1c482 commit 1438622

4 files changed

Lines changed: 152 additions & 103 deletions

File tree

doc/release-notes/rl-2511.section.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Highlights {#sec-nixpkgs-release-25.11-highlights}
44
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
55

6-
- Create the first release note entry in this section!
6+
- Added `allowVariants` to gate availability of package sets like `pkgsLLVM`, `pkgsMusl`, `pkgsZig`, etc.
77

88
## Backward Incompatibilities {#sec-nixpkgs-release-25.11-incompatibilities}
99

pkgs/top-level/config.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ let
137137
'';
138138
};
139139

140+
allowVariants = mkOption {
141+
type = types.bool;
142+
default = true;
143+
description = ''
144+
Whether to expose the nixpkgs variants.
145+
146+
Variants are instances of the current nixpkgs instance with different stdenvs or other applied options.
147+
This allows for using different toolchains, libcs, or global build changes across nixpkgs.
148+
Disabling can ensure nixpkgs is only building for the platform which you specified.
149+
'';
150+
};
151+
140152
cudaSupport = mkMassRebuild {
141153
type = types.bool;
142154
default = false;

pkgs/top-level/stage.nix

Lines changed: 12 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ let
191191

192192
aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
193193

194+
variants = import ./variants.nix {
195+
inherit
196+
lib
197+
nixpkgsFun
198+
stdenv
199+
overlays
200+
makeMuslParsedPlatform
201+
;
202+
};
203+
194204
# stdenvOverrides is used to avoid having multiple of versions
195205
# of certain dependencies that were used in bootstrapping the
196206
# standard environment.
@@ -214,6 +224,7 @@ let
214224
# - pkgsCross.<system> where system is a member of lib.systems.examples
215225
# - pkgsMusl
216226
# - pkgsi686Linux
227+
# NOTE: add new non-critical package sets to "pkgs/top-level/variants.nix"
217228
otherPackageSets = self: super: {
218229
# This maps each entry in lib.systems.examples to its own package
219230
# set. Each of these will contain all packages cross compiled for
@@ -222,69 +233,6 @@ let
222233
# Raspberry Pi.
223234
pkgsCross = lib.mapAttrs (n: crossSystem: nixpkgsFun { inherit crossSystem; }) lib.systems.examples;
224235

225-
pkgsLLVM = nixpkgsFun {
226-
overlays = [
227-
(self': super': {
228-
pkgsLLVM = super';
229-
})
230-
] ++ overlays;
231-
# Bootstrap a cross stdenv using the LLVM toolchain.
232-
# This is currently not possible when compiling natively,
233-
# so we don't need to check hostPlatform != buildPlatform.
234-
crossSystem = stdenv.hostPlatform // {
235-
useLLVM = true;
236-
linker = "lld";
237-
};
238-
};
239-
240-
pkgsArocc = nixpkgsFun {
241-
overlays = [
242-
(self': super': {
243-
pkgsArocc = super';
244-
})
245-
] ++ overlays;
246-
# Bootstrap a cross stdenv using the Aro C compiler.
247-
# This is currently not possible when compiling natively,
248-
# so we don't need to check hostPlatform != buildPlatform.
249-
crossSystem = stdenv.hostPlatform // {
250-
useArocc = true;
251-
linker = "lld";
252-
};
253-
};
254-
255-
pkgsZig = nixpkgsFun {
256-
overlays = [
257-
(self': super': {
258-
pkgsZig = super';
259-
})
260-
] ++ overlays;
261-
# Bootstrap a cross stdenv using the Zig toolchain.
262-
# This is currently not possible when compiling natively,
263-
# so we don't need to check hostPlatform != buildPlatform.
264-
crossSystem = stdenv.hostPlatform // {
265-
useZig = true;
266-
linker = "lld";
267-
};
268-
};
269-
270-
# All packages built with the Musl libc. This will override the
271-
# default GNU libc on Linux systems. Non-Linux systems are not
272-
# supported. 32-bit is also not supported.
273-
pkgsMusl =
274-
if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then
275-
nixpkgsFun {
276-
overlays = [
277-
(self': super': {
278-
pkgsMusl = super';
279-
})
280-
] ++ overlays;
281-
${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = {
282-
config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
283-
};
284-
}
285-
else
286-
throw "Musl libc only supports 64-bit Linux systems.";
287-
288236
# All packages built for i686 Linux.
289237
# Used by wine, firefox with debugging version of Flash, ...
290238
pkgsi686Linux =
@@ -376,45 +324,6 @@ let
376324
// stdenv.hostPlatform.gcc or { };
377325
};
378326
});
379-
380-
# Full package set with rocm on cuda off
381-
# Mostly useful for asserting pkgs.pkgsRocm.torchWithRocm == pkgs.torchWithRocm and similar
382-
pkgsRocm = nixpkgsFun ({
383-
config = super.config // {
384-
cudaSupport = false;
385-
rocmSupport = true;
386-
};
387-
});
388-
389-
pkgsExtraHardening = nixpkgsFun {
390-
overlays = [
391-
(
392-
self': super':
393-
{
394-
pkgsExtraHardening = super';
395-
stdenv = super'.withDefaultHardeningFlags (
396-
super'.stdenv.cc.defaultHardeningFlags
397-
++ [
398-
"shadowstack"
399-
"nostrictaliasing"
400-
"pacret"
401-
"trivialautovarinit"
402-
]
403-
) super'.stdenv;
404-
glibc = super'.glibc.override rec {
405-
enableCET = if self'.stdenv.hostPlatform.isx86_64 then "permissive" else false;
406-
enableCETRuntimeDefault = enableCET != false;
407-
};
408-
}
409-
// lib.optionalAttrs (with super'.stdenv.hostPlatform; isx86_64 && isLinux) {
410-
# causes shadowstack disablement
411-
pcre = super'.pcre.override { enableJit = false; };
412-
pcre-cpp = super'.pcre-cpp.override { enableJit = false; };
413-
pcre16 = super'.pcre16.override { enableJit = false; };
414-
}
415-
)
416-
] ++ overlays;
417-
};
418327
};
419328

420329
# The complete chain of package set builders, applied from top to bottom.
@@ -430,6 +339,7 @@ let
430339
allPackages
431340
otherPackageSets
432341
aliases
342+
variants
433343
configOverrides
434344
]
435345
++ overlays

pkgs/top-level/variants.nix

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
This file contains all of the different variants of nixpkgs instances.
3+
4+
Unlike the other package sets like pkgsCross, pkgsi686Linux, etc., this
5+
contains non-critical package sets. The intent is to be a shorthand
6+
for things like using different toolchains in every package in nixpkgs.
7+
*/
8+
{
9+
lib,
10+
stdenv,
11+
nixpkgsFun,
12+
overlays,
13+
makeMuslParsedPlatform,
14+
}:
15+
let
16+
makeLLVMParsedPlatform =
17+
parsed:
18+
(
19+
parsed
20+
// {
21+
abi = lib.systems.parse.abis.llvm;
22+
}
23+
);
24+
in
25+
self: super: {
26+
pkgsLLVM = nixpkgsFun {
27+
overlays = [
28+
(self': super': {
29+
pkgsLLVM = super';
30+
})
31+
] ++ overlays;
32+
# Bootstrap a cross stdenv using the LLVM toolchain.
33+
# This is currently not possible when compiling natively,
34+
# so we don't need to check hostPlatform != buildPlatform.
35+
crossSystem = stdenv.hostPlatform // {
36+
useLLVM = true;
37+
linker = "lld";
38+
};
39+
};
40+
41+
pkgsArocc = nixpkgsFun {
42+
overlays = [
43+
(self': super': {
44+
pkgsArocc = super';
45+
})
46+
] ++ overlays;
47+
# Bootstrap a cross stdenv using the Aro C compiler.
48+
# This is currently not possible when compiling natively,
49+
# so we don't need to check hostPlatform != buildPlatform.
50+
crossSystem = stdenv.hostPlatform // {
51+
useArocc = true;
52+
linker = "lld";
53+
};
54+
};
55+
56+
pkgsZig = nixpkgsFun {
57+
overlays = [
58+
(self': super': {
59+
pkgsZig = super';
60+
})
61+
] ++ overlays;
62+
# Bootstrap a cross stdenv using the Zig toolchain.
63+
# This is currently not possible when compiling natively,
64+
# so we don't need to check hostPlatform != buildPlatform.
65+
crossSystem = stdenv.hostPlatform // {
66+
useZig = true;
67+
linker = "lld";
68+
};
69+
};
70+
71+
# All packages built with the Musl libc. This will override the
72+
# default GNU libc on Linux systems. Non-Linux systems are not
73+
# supported. 32-bit is also not supported.
74+
pkgsMusl =
75+
if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then
76+
nixpkgsFun {
77+
overlays = [
78+
(self': super': {
79+
pkgsMusl = super';
80+
})
81+
] ++ overlays;
82+
${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = {
83+
config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
84+
};
85+
}
86+
else
87+
throw "Musl libc only supports 64-bit Linux systems.";
88+
89+
# Full package set with rocm on cuda off
90+
# Mostly useful for asserting pkgs.pkgsRocm.torchWithRocm == pkgs.torchWithRocm and similar
91+
pkgsRocm = nixpkgsFun ({
92+
config = super.config // {
93+
cudaSupport = false;
94+
rocmSupport = true;
95+
};
96+
});
97+
98+
pkgsExtraHardening = nixpkgsFun {
99+
overlays = [
100+
(
101+
self': super':
102+
{
103+
pkgsExtraHardening = super';
104+
stdenv = super'.withDefaultHardeningFlags (
105+
super'.stdenv.cc.defaultHardeningFlags
106+
++ [
107+
"shadowstack"
108+
"nostrictaliasing"
109+
"pacret"
110+
"trivialautovarinit"
111+
]
112+
) super'.stdenv;
113+
glibc = super'.glibc.override rec {
114+
enableCET = if self'.stdenv.hostPlatform.isx86_64 then "permissive" else false;
115+
enableCETRuntimeDefault = enableCET != false;
116+
};
117+
}
118+
// lib.optionalAttrs (with super'.stdenv.hostPlatform; isx86_64 && isLinux) {
119+
# causes shadowstack disablement
120+
pcre = super'.pcre.override { enableJit = false; };
121+
pcre-cpp = super'.pcre-cpp.override { enableJit = false; };
122+
pcre16 = super'.pcre16.override { enableJit = false; };
123+
}
124+
)
125+
] ++ overlays;
126+
};
127+
}

0 commit comments

Comments
 (0)