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 ? 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 stdenvAdapters =
89 self: super:
90 let
91 res = import ../stdenv/adapters.nix {
92 inherit lib config;
93 pkgs = self;
94 };
95 in
96 res
97 // {
98 stdenvAdapters = res;
99 };
100
101 trivialBuilders =
102 self: super:
103 import ../build-support/trivial-builders {
104 inherit lib;
105 inherit (self) config;
106 inherit (self) runtimeShell stdenv stdenvNoCC;
107 inherit (self.pkgsBuildHost) jq shellcheck-minimal lndir;
108 };
109
110 stdenvBootstappingAndPlatforms =
111 self: super:
112 let
113 withFallback =
114 thisPkgs:
115 (if adjacentPackages == null then self else thisPkgs) // { recurseForDerivations = false; };
116 in
117 {
118 # Here are package sets of from related stages. They are all in the form
119 # `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
120 # host platform is our build platform, and their target platform is our host
121 # platform. We only care about their host/target platforms, not their build
122 # platform, because the the former two alone affect the interface of the
123 # final package; the build platform is just an implementation detail that
124 # should not leak.
125 pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
126 pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
127 pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
128 pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
129 pkgsHostTarget = self // {
130 recurseForDerivations = false;
131 }; # always `self`
132 pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;
133
134 # Older names for package sets. Use these when only the host platform of the
135 # package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
136 # would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
137 # had more than just `pkgsTargetTarget`).)
138 buildPackages = self.pkgsBuildHost;
139 pkgs = self.pkgsHostTarget;
140 targetPackages = self.pkgsTargetTarget;
141
142 inherit stdenv stdenvNoCC;
143 };
144
145 splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
146
147 allPackages =
148 self: super:
149 let
150 res = import ./all-packages.nix {
151 inherit
152 lib
153 noSysDirs
154 config
155 overlays
156 ;
157 } res self super;
158
159 conflictingAttrs = lib.intersectAttrs res super;
160 in
161 assert lib.assertMsg (conflictingAttrs == { })
162 "The following attributes were defined both in `pkgs/top-level/all-packages.nix` and elsewhere, most likely in `pkgs/by-name/`: ${lib.concatStringsSep ", " (lib.attrNames conflictingAttrs)}";
163 res;
164
165 aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
166
167 variants =
168 self: super:
169 lib.optionalAttrs config.allowVariants (
170 import ./variants.nix {
171 inherit
172 lib
173 nixpkgsFun
174 stdenv
175 overlays
176 ;
177 } self super
178 );
179
180 # stdenvOverrides is used to avoid having multiple of versions
181 # of certain dependencies that were used in bootstrapping the
182 # standard environment.
183 stdenvOverrides = self: super: (super.stdenv.overrides or (_: _: { })) self super;
184
185 # Allow packages to be overridden globally via the `packageOverrides'
186 # configuration option, which must be a function that takes `pkgs'
187 # as an argument and returns a set of new or overridden packages.
188 # The `packageOverrides' function is called with the *original*
189 # (un-overridden) set of packages, allowing packageOverrides
190 # attributes to refer to the original attributes (e.g. "foo =
191 # ... pkgs.foo ...").
192 configOverrides =
193 self: super:
194 lib.optionalAttrs allowCustomOverrides ((config.packageOverrides or (super: { })) super);
195
196 # Convenience attributes for instantitating package sets. Each of
197 # these will instantiate a new version of allPackages. Currently the
198 # following package sets are provided:
199 #
200 # - pkgsCross.<system> where system is a member of lib.systems.examples
201 # - pkgsMusl
202 # - pkgsi686Linux
203 # NOTE: add new non-critical package sets to "pkgs/top-level/variants.nix"
204 otherPackageSets = self: super: {
205 # This maps each entry in lib.systems.examples to its own package
206 # set. Each of these will contain all packages cross compiled for
207 # that target system. For instance, pkgsCross.raspberryPi.hello,
208 # will refer to the "hello" package built for the ARM6-based
209 # Raspberry Pi.
210 pkgsCross = lib.mapAttrs (n: crossSystem: nixpkgsFun { inherit crossSystem; }) lib.systems.examples;
211
212 # All packages built for i686 Linux.
213 # Used by wine, firefox with debugging version of Flash, ...
214 pkgsi686Linux =
215 let
216 isSupported = stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86;
217 in
218 if !config.allowAliases || isSupported then
219 nixpkgsFun {
220 overlays = [
221 (
222 self': super':
223 {
224 pkgsi686Linux = super';
225 }
226 // lib.optionalAttrs (!isSupported) {
227 # Overrides pkgsi686Linux.stdenv.mkDerivation to produce only broken derivations,
228 # when used on a non x86_64-linux platform in CI.
229 # TODO: Remove this, once pkgsi686Linux can become a variant.
230 stdenv = super'.stdenv // {
231 mkDerivation =
232 args:
233 (super'.stdenv.mkDerivation args).overrideAttrs (prevAttrs: {
234 meta = prevAttrs.meta or { } // {
235 broken = true;
236 };
237 });
238 };
239 }
240 )
241 ]
242 ++ overlays;
243 ${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = {
244 config = lib.systems.parse.tripleFromSystem (
245 stdenv.hostPlatform.parsed
246 // {
247 cpu = lib.systems.parse.cpuTypes.i686;
248 }
249 );
250 };
251 }
252 else
253 throw "i686 Linux package set can only be used with the x86 family.";
254
255 # If already linux: the same package set unaltered
256 # Otherwise, return a natively built linux package set for the current cpu architecture string.
257 # (ABI and other details will be set to the default for the cpu/os pair)
258 pkgsLinux =
259 if stdenv.hostPlatform.isLinux then
260 self
261 else
262 nixpkgsFun {
263 localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
264 };
265
266 # Extend the package set with zero or more overlays. This preserves
267 # preexisting overlays. Prefer to initialize with the right overlays
268 # in one go when calling Nixpkgs, for performance and simplicity.
269 appendOverlays =
270 extraOverlays:
271 if extraOverlays == [ ] then self else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
272
273 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
274 # of allocations. DO NOT USE THIS IN NIXPKGS.
275 #
276 # Extend the package set with a single overlay. This preserves
277 # preexisting overlays. Prefer to initialize with the right overlays
278 # in one go when calling Nixpkgs, for performance and simplicity.
279 # Prefer appendOverlays if used repeatedly.
280 extend = f: self.appendOverlays [ f ];
281
282 # Fully static packages.
283 # Currently uses Musl on Linux (couldn’t get static glibc to work).
284 pkgsStatic = nixpkgsFun {
285 overlays = [
286 (self': super': {
287 pkgsStatic = super';
288 })
289 ]
290 ++ overlays;
291 crossSystem = {
292 isStatic = true;
293 config = lib.systems.parse.tripleFromSystem (
294 if stdenv.hostPlatform.isLinux then
295 lib.systems.parse.mkMuslSystem stdenv.hostPlatform.parsed
296 else
297 stdenv.hostPlatform.parsed
298 );
299 gcc =
300 lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; }
301 // stdenv.hostPlatform.gcc or { };
302 };
303 };
304 };
305
306 # The complete chain of package set builders, applied from top to bottom.
307 # stdenvOverlays must be last as it brings package forward from the
308 # previous bootstrapping phases which have already been overlaid.
309 toFix = lib.foldl' (lib.flip lib.extends) (self: { }) (
310 [
311 stdenvBootstappingAndPlatforms
312 stdenvAdapters
313 trivialBuilders
314 splice
315 autoCalledPackages
316 allPackages
317 otherPackageSets
318 aliases
319 variants
320 configOverrides
321 ]
322 ++ overlays
323 ++ [
324 stdenvOverrides
325 ]
326 );
327
328in
329# Return the complete set of packages.
330lib.fix toFix