Repository navigation
Expand file tree
/
Copy pathdefault.nix
More file actions
209 lines (178 loc) · 7.86 KB
/
Copy pathdefault.nix
File metadata and controls
209 lines (178 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
The entry point of this package set, and the one impure file in it. It:
1. Elaborates `localSystem` and `crossSystem` with defaults as needed.
2. Evaluates `config`, allowing it to depend on the final package set
3. Defaults to no non-standard config and no cross-compilation target
4. Uses the above to infer the default standard environment's (stdenv)
stages if none are provided
5. Folds the stages to yield the final fully booted package set for the
chosen stdenv
`builtins.currentSystem` below is the only impurity here: everything else
is derived from the arguments. Pass `localSystem` (or the legacy `system`)
to evaluate for a platform other than the one Nix is running on.
TODO: port minfeatures
*/
{
# Pre-resolved pin sources, as returned by `import ./pins.nix`. Passing an
# attrset of store paths here (e.g. from a rendered `pins-offline.nix`)
# allows evaluation without network access.
pins ? import ./pins.nix,
# The platform packages are built on -- the "build" platform, in GNU
# Autotools parlance. See `lib.systems` for the division of labour between
# these two `*System`s and the three `*Platform`s they elaborate into.
# Passing it wins over `system`, which is only consulted for the default.
localSystem ? { inherit system; },
# The legacy spelling of `localSystem`, carrying a bare system double
# rather than an attribute set. It stays a named argument because nix's
# auto-call only fills formals a function declares, so an argument reachable
# any other way could not be set with `--argstr`.
system ? builtins.currentSystem,
# The platform packages will ultimately run on -- the "host" platform.
# Defaults to `localSystem` rather than to `null`, so a native build is the
# two being equal rather than the cross target being absent. Note that an
# explicit `crossSystem = null` is not currently accepted.
crossSystem ? localSystem,
# Configuration for the package set, as either an attribute set or a
# function of the final packages. Evaluated through `config/` as a module.
config ? { },
# Set to false to make `lib.fileset` abort on use, which the package set
# forbids internally until <https://github.com/NixOS/nix/issues/11503> is
# fixed.
# TODO: remove once that bug is fixed upstream
__allowFileset ? true,
# Extra modules folded into the `config` evaluation alongside `config/`.
# TODO: document this
modules ? [ ],
# Overlays extending the package set. Each is a function of the final and
# previous package sets, and they take part in its fixed point.
overlays ? [ ],
# Overlays applied only to the packages built for the host platform, not to
# the native ones used to build them.
crossOverlays ? [ ],
}@args:
let
inputs = { inherit localSystem crossSystem config; };
in
let
# A function returning the list of bootstrapping stages to fold into the
# final package set. `stages` below shows the arguments it is given.
stdenvStages = import ./stdenv;
pristineLib = import ./lib.nix { inherit pins; };
lib =
if __allowFileset then
pristineLib
else
pristineLib.extend (
_: _: {
fileset = abort ''
The use of `lib.fileset` is currently forbidden in Nixpkgs due to the
upstream Nix bug <https://github.com/NixOS/nix/issues/11503>. This
causes difficult‐to‐debug errors when combined with chroot stores,
such as in the NixOS installer.
For packages that require source to be vendored inside Nixpkgs,
please use a subdirectory of the package instead.
'';
}
);
inherit (lib) throwIfNot;
checked =
(throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list.")
(throwIfNot (lib.all lib.isFunction overlays) "All overlays passed to nixpkgs must be functions.")
(throwIfNot (lib.isList crossOverlays) "The crossOverlays argument to nixpkgs must be a list.")
(
throwIfNot (lib.all lib.isFunction crossOverlays) "All crossOverlays passed to nixpkgs must be functions."
);
elaboratedLocalSystem = lib.systems.elaborate inputs.localSystem;
# A native build must come out as `elaboratedLocalSystem` itself, not an
# equal copy: the sharing is what later makes `hostPlatform == buildPlatform`
# cheap, and `lib.systems.equals` documents why that matters.
#
# Two systems cannot be compared as passed, only once elaborated -- given
#
# localSystem = { system = "x86_64-linux"; };
# crossSystem = { config = "x86_64-unknown-linux-gnu"; };
#
# both name the same platform, since the vendor and ABI are inferred from the
# system double. Equal *arguments* do imply equal systems, though, so that
# case short-circuits and skips the second elaboration.
elaboratedCrossSystem =
if inputs.crossSystem == inputs.localSystem then
elaboratedLocalSystem
else
let
elaboratedCrossSystem = lib.systems.elaborate inputs.crossSystem;
in
if lib.systems.equals elaboratedCrossSystem elaboratedLocalSystem then
elaboratedLocalSystem
else
elaboratedCrossSystem;
configEval = lib.evalModules {
class = "nixpkgsConfig";
modules = [
./config/build-options.nix
./config/package-options.nix
./config/overlays.nix
(lib.mkRenamedOptionModule [ "allowUnfreePackages" ] [ "licenses" "accept" ])
{
_file = "nixpkgs.config";
# Allow both:
# { /* the config */ } and
# { pkgs, ... } : { /* the config */ }
config =
if lib.isFunction inputs.config then inputs.config { inherit lib pkgs; } else inputs.config;
}
]
++ modules;
};
config =
lib.asserts.checkAssertWarn configEval.config.assertions configEval.config.warnings
configEval.config;
# A few packages make a new package set to draw their dependencies from.
# (Currently to get a cross tool chain, or forced-i686 package.) Rather than
# give `top-level.nix` all the arguments to this function, even ones that
# don't concern it, we give it this function to "re-call" nixpkgs, inheriting
# whatever arguments it doesn't explicitly provide. This way,
# `top-level.nix` doesn't know more than it needs too.
#
# It's OK that `args` doesn't include default arguments from this file:
# they'll be deterministically inferred. In fact we must *not* include them,
# because it's important that if some parameter which affects the default is
# substituted with a different argument, the default is re-inferred.
#
# To put this in concrete terms, this function is basically just used today to
# use package for a different platform for the current platform (namely cross
# compiling toolchains and 32-bit packages on x86_64). In both those cases we
# want the provided non-native `localSystem` argument to affect the stdenv
# chosen.
#
# NB!!! This takes its `config` from `args`, i.e. the argument as the caller
# wrote it -- the same thing `inputs.config` holds, not the `config` bound
# above. That distinction has to survive every re-entry, because the
# `evalModules` step turning the one into the other is not idempotent. In
# other words, if you add `config` to `newArgs`, expect strange very hard to
# debug errors! (Yes, I'm speaking from experience here.)
nixpkgsFun = newArgs: import ./. (args // newArgs);
# Partially apply some arguments for building bootstrapping stage pkgs
# sets. Only apply arguments which no stdenv would want to override.
allPackages =
newArgs:
import ./stdenv/stage.nix (
{
inherit lib nixpkgsFun;
}
// newArgs
);
boot = import ./stdenv/booter.nix { inherit lib allPackages; };
stages = stdenvStages {
inherit
lib
config
overlays
crossOverlays
;
localSystem = elaboratedLocalSystem;
crossSystem = elaboratedCrossSystem;
};
pkgs = boot stages;
in
checked pkgs