forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
235 lines (201 loc) · 8.03 KB
/
default.nix
File metadata and controls
235 lines (201 loc) · 8.03 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
This function composes the Nix Packages collection. It:
1. Elaborates `localSystem` and `crossSystem` with defaults as needed.
2. Applies the final stage to the given `config` if it is a function
3. Defaults to no non-standard config and no cross-compilation target
4. Uses the above to infer the default standard environment's (stdenv's)
stages if no stdenv's are provided
5. Folds the stages to yield the final fully booted package set for the
chosen stdenv
Use `impure.nix` to also infer the `system` based on the one on which
evaluation is taking place, and the configuration from environment variables
or dot-files.
*/
let
# We hoist this above the closure so that the same thunk is shared
# between multiple imports of Nixpkgs. This ensures that commands
# like `nix eval nixpkgs#legacyPackages.x86_64-darwin.pkgsStatic.hello`
# print only one warning, which would otherwise be spammy in common
# scenarios that instantiate many copies of Nixpkgs.
#
# Unfortunately, flakes’ handling of transitive dependencies mean
# that it’s still likely users will see multiple warnings, but
# there’s nothing we can do about that within the constraints of the
# Nix language.
x86_64DarwinDeprecationWarning =
pristineLib.warn
"Nixpkgs 26.05 will be the last release to support x86_64-darwin; see https://nixos.org/manual/nixpkgs/unstable/release-notes#x86_64-darwin-26.05"
(x: x);
pristineLib = import ../../lib;
in
{
# The system packages will be built on. See the manual for the
# subtle division of labor between these two `*System`s and the three
# `*Platform`s.
localSystem,
# The system packages will ultimately be run on.
crossSystem ? localSystem,
# Allow a configuration attribute set to be passed in as an argument.
config ? { },
# Temporary hack to let Nixpkgs forbid internal use of `lib.fileset`
# until <https://github.com/NixOS/nix/issues/11503> is fixed.
__allowFileset ? true,
# List of overlays layers used to extend Nixpkgs.
overlays ? [ ],
# List of overlays to apply to target packages only.
crossOverlays ? [ ],
# A function booting the final package set for a specific standard
# environment. See below for the arguments given to that function, the type of
# list it returns.
stdenvStages ? import ../stdenv,
# Temporary parameter to unify nixpkgs/pkgs evaluation
# Internal, do not use this manually!
# Will be removed again within the next releases
_configDefinitions ? null,
# Ignore unexpected args.
...
}@args:
let # Rename the function arguments
config0 = config;
crossSystem0 = crossSystem;
in
let
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.")
(
if
(
((localSystem.isDarwin && localSystem.isx86) || (crossSystem.isDarwin && crossSystem.isx86))
&& config.allowDeprecatedx86_64Darwin == false
)
then
x86_64DarwinDeprecationWarning
else
x:
x throwIfNot (lib.all lib.isFunction crossOverlays)
"All crossOverlays passed to nixpkgs must be functions."
)
(
throwIfNot (_configDefinitions == null || config0 == { })
"The `_configDefinitions` argument is an internal interface and must not be combined with `config`."
);
localSystem = lib.systems.elaborate args.localSystem;
# Condition preserves sharing which in turn affects equality.
#
# See `lib.systems.equals` documentation for more details.
#
# Note that it is generally not possible to compare systems as given in
# parameters, e.g. if systems are initialized as
#
# localSystem = { system = "x86_64-linux"; };
# crossSystem = { config = "x86_64-unknown-linux-gnu"; };
#
# Both systems are semantically equivalent as the same vendor and ABI are
# inferred from the system double in `localSystem`.
crossSystem =
let
system = lib.systems.elaborate crossSystem0;
in
if crossSystem0 == null || lib.systems.equals system localSystem then localSystem else system;
# Allow both:
# { /* the config */ } and
# { lib, pkgs, ... } : { /* the config */ }
config1 = if lib.isFunction config0 then config0 { inherit lib pkgs; } else config0;
configEval = lib.evalModules {
modules = [
./config.nix
]
++ (
if _configDefinitions != null then
map (def: lib.modules.setDefaultModuleLocation def.file def.value) _configDefinitions
else
[
{
_file = "nixpkgs.config";
config = config1;
}
]
);
class = "nixpkgsConfig";
};
# take all the rest as-is
config =
let
failedAssertionsString = lib.concatMapStringsSep "\n" (x: "- ${x.message}") (
lib.filter (x: !x.assertion) configEval.config.assertions
);
in
if failedAssertionsString != "" then
throw "Failed assertions:\n${failedAssertionsString}"
else
lib.showWarnings 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 `all-packages.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,
# `all-packages.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 thing gets its `config` argument from `args`, i.e. it's actually
# `config0`. It is important to keep it to `config0` format (as opposed to the
# result of `evalModules`, i.e. the `config` variable above) throughout all
# nixpkgs evaluations since the above function `config0 -> config` implemented
# via `evalModules` 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 ./stage.nix (
{
inherit lib nixpkgsFun;
}
// newArgs
);
boot = import ../stdenv/booter.nix { inherit lib allPackages; };
stages = stdenvStages {
inherit
lib
localSystem
crossSystem
config
overlays
crossOverlays
;
};
pkgs = boot stages;
in
checked pkgs