nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 ? (
58 stdenv.override {
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 stdenv = stdenv.override (o: {
174 callPackage = self.callPackage;
175 });
176 stdenvNoCC = stdenvNoCC.override (o: {
177 callPackage = self.callPackage;
178 });
179 };
180
181 splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
182
183 allPackages =
184 self: super:
185 let
186 res = import ./all-packages.nix {
187 inherit
188 lib
189 noSysDirs
190 config
191 overlays
192 ;
193 } res self super;
194 in
195 res;
196
197 aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
198
199 variants =
200 self: super:
201 lib.optionalAttrs config.allowVariants (
202 import ./variants.nix {
203 inherit
204 lib
205 nixpkgsFun
206 stdenv
207 overlays
208 makeMuslParsedPlatform
209 ;
210 } self super
211 );
212
213 # stdenvOverrides is used to avoid having multiple of versions
214 # of certain dependencies that were used in bootstrapping the
215 # standard environment.
216 stdenvOverrides = self: super: (super.stdenv.overrides or (_: _: { })) self super;
217
218 # Allow packages to be overridden globally via the `packageOverrides'
219 # configuration option, which must be a function that takes `pkgs'
220 # as an argument and returns a set of new or overridden packages.
221 # The `packageOverrides' function is called with the *original*
222 # (un-overridden) set of packages, allowing packageOverrides
223 # attributes to refer to the original attributes (e.g. "foo =
224 # ... pkgs.foo ...").
225 configOverrides =
226 self: super:
227 lib.optionalAttrs allowCustomOverrides ((config.packageOverrides or (super: { })) super);
228
229 # Convenience attributes for instantitating package sets. Each of
230 # these will instantiate a new version of allPackages. Currently the
231 # following package sets are provided:
232 #
233 # - pkgsCross.<system> where system is a member of lib.systems.examples
234 # - pkgsMusl
235 # - pkgsi686Linux
236 # NOTE: add new non-critical package sets to "pkgs/top-level/variants.nix"
237 otherPackageSets = self: super: {
238 # This maps each entry in lib.systems.examples to its own package
239 # set. Each of these will contain all packages cross compiled for
240 # that target system. For instance, pkgsCross.raspberryPi.hello,
241 # will refer to the "hello" package built for the ARM6-based
242 # Raspberry Pi.
243 pkgsCross = lib.mapAttrs (n: crossSystem: nixpkgsFun { inherit crossSystem; }) lib.systems.examples;
244
245 # All packages built for i686 Linux.
246 # Used by wine, firefox with debugging version of Flash, ...
247 pkgsi686Linux =
248 let
249 isSupported = stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86;
250 in
251 if !config.allowAliases || isSupported then
252 nixpkgsFun {
253 overlays = [
254 (
255 self': super':
256 {
257 pkgsi686Linux = super';
258 }
259 // lib.optionalAttrs (!isSupported) {
260 # Overrides pkgsi686Linux.stdenv.mkDerivation to produce only broken derivations,
261 # when used on a non x86_64-linux platform in CI.
262 # TODO: Remove this, once pkgsi686Linux can become a variant.
263 stdenv = super'.stdenv // {
264 mkDerivation =
265 args:
266 (super'.stdenv.mkDerivation args).overrideAttrs (prevAttrs: {
267 meta = prevAttrs.meta or { } // {
268 broken = true;
269 };
270 });
271 };
272 }
273 )
274 ]
275 ++ overlays;
276 ${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = {
277 config = lib.systems.parse.tripleFromSystem (
278 stdenv.hostPlatform.parsed
279 // {
280 cpu = lib.systems.parse.cpuTypes.i686;
281 }
282 );
283 };
284 }
285 else
286 throw "i686 Linux package set can only be used with the x86 family.";
287
288 # If already linux: the same package set unaltered
289 # Otherwise, return a natively built linux package set for the current cpu architecture string.
290 # (ABI and other details will be set to the default for the cpu/os pair)
291 pkgsLinux =
292 if stdenv.hostPlatform.isLinux then
293 self
294 else
295 nixpkgsFun {
296 localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
297 };
298
299 # Extend the package set with zero or more overlays. This preserves
300 # preexisting overlays. Prefer to initialize with the right overlays
301 # in one go when calling Nixpkgs, for performance and simplicity.
302 appendOverlays =
303 extraOverlays:
304 if extraOverlays == [ ] then self else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
305
306 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
307 # of allocations. DO NOT USE THIS IN NIXPKGS.
308 #
309 # Extend the package set with a single overlay. This preserves
310 # preexisting overlays. Prefer to initialize with the right overlays
311 # in one go when calling Nixpkgs, for performance and simplicity.
312 # Prefer appendOverlays if used repeatedly.
313 extend = f: self.appendOverlays [ f ];
314
315 # Fully static packages.
316 # Currently uses Musl on Linux (couldn’t get static glibc to work).
317 pkgsStatic = nixpkgsFun ({
318 overlays = [
319 (self': super': {
320 pkgsStatic = super';
321 })
322 ]
323 ++ overlays;
324 crossSystem = {
325 isStatic = true;
326 config = lib.systems.parse.tripleFromSystem (
327 if stdenv.hostPlatform.isLinux then
328 makeMuslParsedPlatform stdenv.hostPlatform.parsed
329 else
330 stdenv.hostPlatform.parsed
331 );
332 gcc =
333 lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; }
334 // stdenv.hostPlatform.gcc or { };
335 };
336 });
337 };
338
339 # The complete chain of package set builders, applied from top to bottom.
340 # stdenvOverlays must be last as it brings package forward from the
341 # previous bootstrapping phases which have already been overlaid.
342 toFix = lib.foldl' (lib.flip lib.extends) (self: { }) (
343 [
344 stdenvBootstappingAndPlatforms
345 stdenvAdapters
346 trivialBuilders
347 splice
348 autoCalledPackages
349 allPackages
350 otherPackageSets
351 aliases
352 variants
353 configOverrides
354 ]
355 ++ overlays
356 ++ [
357 stdenvOverrides
358 ]
359 );
360
361in
362# Return the complete set of packages.
363lib.fix toFix