1/*
2 This function composes the Nix Packages collection. It:
3
4 1. Elaborates `localSystem` and `crossSystem` with defaults as needed.
5
6 2. Applies the final stage to the given `config` if it is a function
7
8 3. Defaults to no non-standard config and no cross-compilation target
9
10 4. Uses the above to infer the default standard environment's (stdenv's)
11 stages if no stdenv's are provided
12
13 5. Folds the stages to yield the final fully booted package set for the
14 chosen stdenv
15
16 Use `impure.nix` to also infer the `system` based on the one on which
17 evaluation is taking place, and the configuration from environment variables
18 or dot-files.
19*/
20
21{
22 # The system packages will be built on. See the manual for the
23 # subtle division of labor between these two `*System`s and the three
24 # `*Platform`s.
25 localSystem,
26
27 # The system packages will ultimately be run on.
28 crossSystem ? localSystem,
29
30 # Allow a configuration attribute set to be passed in as an argument.
31 config ? { },
32
33 # Temporary hack to let Nixpkgs forbid internal use of `lib.fileset`
34 # until <https://github.com/NixOS/nix/issues/11503> is fixed.
35 __allowFileset ? true,
36
37 # List of overlays layers used to extend Nixpkgs.
38 overlays ? [ ],
39
40 # List of overlays to apply to target packages only.
41 crossOverlays ? [ ],
42
43 # A function booting the final package set for a specific standard
44 # environment. See below for the arguments given to that function, the type of
45 # list it returns.
46 stdenvStages ? import ../stdenv,
47
48 # Ignore unexpected args.
49 ...
50}@args:
51
52let # Rename the function arguments
53 config0 = config;
54 crossSystem0 = crossSystem;
55
56in
57let
58 pristineLib = import ../../lib;
59
60 lib =
61 if __allowFileset then
62 pristineLib
63 else
64 pristineLib.extend (
65 _: _: {
66 fileset = abort ''
67
68 The use of `lib.fileset` is currently forbidden in Nixpkgs due to the
69 upstream Nix bug <https://github.com/NixOS/nix/issues/11503>. This
70 causes difficult‐to‐debug errors when combined with chroot stores,
71 such as in the NixOS installer.
72
73 For packages that require source to be vendored inside Nixpkgs,
74 please use a subdirectory of the package instead.
75 '';
76 }
77 );
78
79 inherit (lib) throwIfNot;
80
81 checked =
82 throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list." lib.foldr
83 (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.")
84 (r: r)
85 overlays
86 throwIfNot
87 (lib.isList crossOverlays)
88 "The crossOverlays argument to nixpkgs must be a list."
89 lib.foldr
90 (x: throwIfNot (lib.isFunction x) "All crossOverlays passed to nixpkgs must be functions.")
91 (r: r)
92 crossOverlays;
93
94 localSystem = lib.systems.elaborate args.localSystem;
95
96 # Condition preserves sharing which in turn affects equality.
97 #
98 # See `lib.systems.equals` documentation for more details.
99 #
100 # Note that it is generally not possible to compare systems as given in
101 # parameters, e.g. if systems are initialized as
102 #
103 # localSystem = { system = "x86_64-linux"; };
104 # crossSystem = { config = "x86_64-unknown-linux-gnu"; };
105 #
106 # Both systems are semantically equivalent as the same vendor and ABI are
107 # inferred from the system double in `localSystem`.
108 crossSystem =
109 let
110 system = lib.systems.elaborate crossSystem0;
111 in
112 if crossSystem0 == null || lib.systems.equals system localSystem then localSystem else system;
113
114 # Allow both:
115 # { /* the config */ } and
116 # { pkgs, ... } : { /* the config */ }
117 config1 = if lib.isFunction config0 then config0 { inherit pkgs; } else config0;
118
119 configEval = lib.evalModules {
120 modules = [
121 ./config.nix
122 (
123 { options, ... }:
124 {
125 _file = "nixpkgs.config";
126 config = config1;
127 }
128 )
129 ];
130 class = "nixpkgsConfig";
131 };
132
133 # take all the rest as-is
134 config = lib.showWarnings configEval.config.warnings configEval.config;
135
136 # A few packages make a new package set to draw their dependencies from.
137 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than
138 # give `all-packages.nix` all the arguments to this function, even ones that
139 # don't concern it, we give it this function to "re-call" nixpkgs, inheriting
140 # whatever arguments it doesn't explicitly provide. This way,
141 # `all-packages.nix` doesn't know more than it needs too.
142 #
143 # It's OK that `args` doesn't include default arguments from this file:
144 # they'll be deterministically inferred. In fact we must *not* include them,
145 # because it's important that if some parameter which affects the default is
146 # substituted with a different argument, the default is re-inferred.
147 #
148 # To put this in concrete terms, this function is basically just used today to
149 # use package for a different platform for the current platform (namely cross
150 # compiling toolchains and 32-bit packages on x86_64). In both those cases we
151 # want the provided non-native `localSystem` argument to affect the stdenv
152 # chosen.
153 #
154 # NB!!! This thing gets its `config` argument from `args`, i.e. it's actually
155 # `config0`. It is important to keep it to `config0` format (as opposed to the
156 # result of `evalModules`, i.e. the `config` variable above) throughout all
157 # nixpkgs evaluations since the above function `config0 -> config` implemented
158 # via `evalModules` is not idempotent. In other words, if you add `config` to
159 # `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from
160 # experience here.)
161 nixpkgsFun = newArgs: import ./. (args // newArgs);
162
163 # Partially apply some arguments for building bootstrapping stage pkgs
164 # sets. Only apply arguments which no stdenv would want to override.
165 allPackages =
166 newArgs:
167 import ./stage.nix (
168 {
169 inherit lib nixpkgsFun;
170 }
171 // newArgs
172 );
173
174 boot = import ../stdenv/booter.nix { inherit lib allPackages; };
175
176 stages = stdenvStages {
177 inherit
178 lib
179 localSystem
180 crossSystem
181 config
182 overlays
183 crossOverlays
184 ;
185 };
186
187 pkgs = boot stages;
188
189in
190checked pkgs