1/*
2 This file composes a single bootstrapping stage of the Nix Packages
3 collection. That is, it imports the functions that build the various
4 packages, and calls them with appropriate arguments. The result is a set of
5 all the packages in the Nix Packages collection for some particular platform
6 for some particular stage.
7
8 Default arguments are only provided for bootstrapping
9 arguments. Normal users should not import this directly but instead
10 import `pkgs/default.nix` or `default.nix`.
11*/
12
13let
14 # An overlay to auto-call packages in ../by-name.
15 # By defining it at the top of the file,
16 # this value gets reused even if this file is imported multiple times,
17 # thanks to Nix's import-value cache.
18 autoCalledPackages = import ./by-name-overlay.nix ../by-name;
19in
20
21{
22 ## Misc parameters kept the same for all stages
23 ##
24
25 # Utility functions, could just import but passing in for efficiency
26 lib,
27
28 # Use to reevaluate Nixpkgs
29 nixpkgsFun,
30
31 ## Other parameters
32 ##
33
34 # Either null or an object in the form:
35 #
36 # {
37 # pkgsBuildBuild = ...;
38 # pkgsBuildHost = ...;
39 # pkgsBuildTarget = ...;
40 # pkgsHostHost = ...;
41 # # pkgsHostTarget skipped on purpose.
42 # pkgsTargetTarget ...;
43 # }
44 #
45 # These are references to adjacent bootstrapping stages. The more familiar
46 # `buildPackages` and `targetPackages` are defined in terms of them. If null,
47 # they are instead defined internally as the current stage. This allows us to
48 # avoid expensive splicing. `pkgsHostTarget` is skipped because it is always
49 # defined as the current stage.
50 adjacentPackages,
51
52 # The standard environment to use for building packages.
53 stdenv,
54
55 # `stdenv` without a C compiler. Passing in this helps avoid infinite
56 # recursions, and may eventually replace passing in the full stdenv.
57 stdenvNoCC ? stdenv.override (
58 {
59 cc = null;
60 hasCC = false;
61 }
62 # Darwin doesn’t need an SDK in `stdenvNoCC`. Dropping it shrinks the closure
63 # size down from ~1 GiB to ~83 MiB, which is a considerable reduction.
64 // lib.optionalAttrs stdenv.hostPlatform.isDarwin { extraBuildInputs = [ ]; }
65 ),
66
67 # This is used because stdenv replacement and the stdenvCross do benefit from
68 # the overridden configuration provided by the user, as opposed to the normal
69 # bootstrapping stdenvs.
70 allowCustomOverrides,
71
72 # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
73 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
74 # in standard system directories (/usr/include, etc.)
75 noSysDirs ?
76 stdenv.buildPlatform.system != "x86_64-solaris"
77 && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu",
78
79 # The configuration attribute set
80 config,
81
82 # A list of overlays (Additional `self: super: { .. }` customization
83 # functions) to be fixed together in the produced package set
84 overlays,
85}@args:
86
87let
88 # This is a function from parsed platforms (like
89 # stdenv.hostPlatform.parsed) to parsed platforms.
90 makeMuslParsedPlatform =
91 parsed:
92 # The following line guarantees that the output of this function
93 # is a well-formed platform with no missing fields. It will be
94 # uncommented in a separate PR, in case it breaks the build.
95 #(x: lib.trivial.pipe x [ (x: builtins.removeAttrs x [ "_type" ]) lib.systems.parse.mkSystem ])
96 (
97 parsed
98 // {
99 abi =
100 {
101 gnu = lib.systems.parse.abis.musl;
102 gnueabi = lib.systems.parse.abis.musleabi;
103 gnueabihf = lib.systems.parse.abis.musleabihf;
104 gnuabin32 = lib.systems.parse.abis.muslabin32;
105 gnuabi64 = lib.systems.parse.abis.muslabi64;
106 gnuabielfv2 = lib.systems.parse.abis.musl;
107 gnuabielfv1 = lib.systems.parse.abis.musl;
108 # The following two entries ensure that this function is idempotent.
109 musleabi = lib.systems.parse.abis.musleabi;
110 musleabihf = lib.systems.parse.abis.musleabihf;
111 muslabin32 = lib.systems.parse.abis.muslabin32;
112 muslabi64 = lib.systems.parse.abis.muslabi64;
113 }
114 .${parsed.abi.name} or lib.systems.parse.abis.musl;
115 }
116 );
117
118 stdenvAdapters =
119 self: super:
120 let
121 res = import ../stdenv/adapters.nix {
122 inherit lib config;
123 pkgs = self;
124 };
125 in
126 res
127 // {
128 stdenvAdapters = res;
129 };
130
131 trivialBuilders =
132 self: super:
133 import ../build-support/trivial-builders {
134 inherit lib;
135 inherit (self) config;
136 inherit (self) runtimeShell stdenv stdenvNoCC;
137 inherit (self.pkgsBuildHost) jq shellcheck-minimal;
138 inherit (self.pkgsBuildHost.xorg) lndir;
139 };
140
141 stdenvBootstappingAndPlatforms =
142 self: super:
143 let
144 withFallback =
145 thisPkgs:
146 (if adjacentPackages == null then self else thisPkgs) // { recurseForDerivations = false; };
147 in
148 {
149 # Here are package sets of from related stages. They are all in the form
150 # `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
151 # host platform is our build platform, and their target platform is our host
152 # platform. We only care about their host/target platforms, not their build
153 # platform, because the the former two alone affect the interface of the
154 # final package; the build platform is just an implementation detail that
155 # should not leak.
156 pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
157 pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
158 pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
159 pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
160 pkgsHostTarget = self // {
161 recurseForDerivations = false;
162 }; # always `self`
163 pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;
164
165 # Older names for package sets. Use these when only the host platform of the
166 # package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
167 # would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
168 # had more than just `pkgsTargetTarget`).)
169 buildPackages = self.pkgsBuildHost;
170 pkgs = self.pkgsHostTarget;
171 targetPackages = self.pkgsTargetTarget;
172
173 inherit stdenv stdenvNoCC;
174 };
175
176 splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
177
178 allPackages =
179 self: super:
180 let
181 res = import ./all-packages.nix {
182 inherit
183 lib
184 noSysDirs
185 config
186 overlays
187 ;
188 } res self super;
189 in
190 res;
191
192 aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
193
194 variants =
195 self: super:
196 lib.optionalAttrs config.allowVariants (
197 import ./variants.nix {
198 inherit
199 lib
200 nixpkgsFun
201 stdenv
202 overlays
203 makeMuslParsedPlatform
204 ;
205 } self super
206 );
207
208 # stdenvOverrides is used to avoid having multiple of versions
209 # of certain dependencies that were used in bootstrapping the
210 # standard environment.
211 stdenvOverrides = self: super: (super.stdenv.overrides or (_: _: { })) self super;
212
213 # Allow packages to be overridden globally via the `packageOverrides'
214 # configuration option, which must be a function that takes `pkgs'
215 # as an argument and returns a set of new or overridden packages.
216 # The `packageOverrides' function is called with the *original*
217 # (un-overridden) set of packages, allowing packageOverrides
218 # attributes to refer to the original attributes (e.g. "foo =
219 # ... pkgs.foo ...").
220 configOverrides =
221 self: super:
222 lib.optionalAttrs allowCustomOverrides ((config.packageOverrides or (super: { })) super);
223
224 # Convenience attributes for instantitating package sets. Each of
225 # these will instantiate a new version of allPackages. Currently the
226 # following package sets are provided:
227 #
228 # - pkgsCross.<system> where system is a member of lib.systems.examples
229 # - pkgsMusl
230 # - pkgsi686Linux
231 # NOTE: add new non-critical package sets to "pkgs/top-level/variants.nix"
232 otherPackageSets = self: super: {
233 # This maps each entry in lib.systems.examples to its own package
234 # set. Each of these will contain all packages cross compiled for
235 # that target system. For instance, pkgsCross.raspberryPi.hello,
236 # will refer to the "hello" package built for the ARM6-based
237 # Raspberry Pi.
238 pkgsCross = lib.mapAttrs (n: crossSystem: nixpkgsFun { inherit crossSystem; }) lib.systems.examples;
239
240 # All packages built for i686 Linux.
241 # Used by wine, firefox with debugging version of Flash, ...
242 pkgsi686Linux =
243 let
244 isSupported = stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86;
245 in
246 if !config.allowAliases || isSupported then
247 nixpkgsFun {
248 overlays = [
249 (
250 self': super':
251 {
252 pkgsi686Linux = super';
253 }
254 // lib.optionalAttrs (!isSupported) {
255 # Overrides pkgsi686Linux.stdenv.mkDerivation to produce only broken derivations,
256 # when used on a non x86_64-linux platform in CI.
257 # TODO: Remove this, once pkgsi686Linux can become a variant.
258 stdenv = super'.stdenv // {
259 mkDerivation =
260 args:
261 (super'.stdenv.mkDerivation args).overrideAttrs (prevAttrs: {
262 meta = prevAttrs.meta or { } // {
263 broken = true;
264 };
265 });
266 };
267 }
268 )
269 ]
270 ++ overlays;
271 ${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = {
272 config = lib.systems.parse.tripleFromSystem (
273 stdenv.hostPlatform.parsed
274 // {
275 cpu = lib.systems.parse.cpuTypes.i686;
276 }
277 );
278 };
279 }
280 else
281 throw "i686 Linux package set can only be used with the x86 family.";
282
283 # If already linux: the same package set unaltered
284 # Otherwise, return a natively built linux package set for the current cpu architecture string.
285 # (ABI and other details will be set to the default for the cpu/os pair)
286 pkgsLinux =
287 if stdenv.hostPlatform.isLinux then
288 self
289 else
290 nixpkgsFun {
291 localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
292 };
293
294 # Extend the package set with zero or more overlays. This preserves
295 # preexisting overlays. Prefer to initialize with the right overlays
296 # in one go when calling Nixpkgs, for performance and simplicity.
297 appendOverlays =
298 extraOverlays:
299 if extraOverlays == [ ] then self else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
300
301 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
302 # of allocations. DO NOT USE THIS IN NIXPKGS.
303 #
304 # Extend the package set with a single overlay. This preserves
305 # preexisting overlays. Prefer to initialize with the right overlays
306 # in one go when calling Nixpkgs, for performance and simplicity.
307 # Prefer appendOverlays if used repeatedly.
308 extend = f: self.appendOverlays [ f ];
309
310 # Fully static packages.
311 # Currently uses Musl on Linux (couldn’t get static glibc to work).
312 pkgsStatic = nixpkgsFun ({
313 overlays = [
314 (self': super': {
315 pkgsStatic = super';
316 })
317 ]
318 ++ overlays;
319 crossSystem = {
320 isStatic = true;
321 config = lib.systems.parse.tripleFromSystem (
322 if stdenv.hostPlatform.isLinux then
323 makeMuslParsedPlatform stdenv.hostPlatform.parsed
324 else
325 stdenv.hostPlatform.parsed
326 );
327 gcc =
328 lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; }
329 // stdenv.hostPlatform.gcc or { };
330 };
331 });
332 };
333
334 # The complete chain of package set builders, applied from top to bottom.
335 # stdenvOverlays must be last as it brings package forward from the
336 # previous bootstrapping phases which have already been overlaid.
337 toFix = lib.foldl' (lib.flip lib.extends) (self: { }) (
338 [
339 stdenvBootstappingAndPlatforms
340 stdenvAdapters
341 trivialBuilders
342 splice
343 autoCalledPackages
344 allPackages
345 otherPackageSets
346 aliases
347 variants
348 configOverrides
349 ]
350 ++ overlays
351 ++ [
352 stdenvOverrides
353 ]
354 );
355
356in
357# Return the complete set of packages.
358lib.fix toFix