1/* This function composes the Nix Packages collection. It:
2
3 1. Elaborates `localSystem` and `crossSystem` with defaults as needed.
4
5 2. Applies the final stage to the given `config` if it is a function
6
7 3. Defaults to no non-standard config and no cross-compilation target
8
9 4. Uses the above to infer the default standard environment's (stdenv's)
10 stages if no stdenv's are provided
11
12 5. Folds the stages to yield the final fully booted package set for the
13 chosen stdenv
14
15 Use `impure.nix` to also infer the `system` based on the one on which
16 evaluation is taking place, and the configuration from environment variables
17 or dot-files. */
18
19{ # The system packages will be built on. See the manual for the
20 # subtle division of labor between these two `*System`s and the three
21 # `*Platform`s.
22 localSystem
23
24, # The system packages will ultimately be run on.
25 crossSystem ? localSystem
26
27, # Allow a configuration attribute set to be passed in as an argument.
28 config ? {}
29
30, # List of overlays layers used to extend Nixpkgs.
31 overlays ? []
32
33, # List of overlays to apply to target packages only.
34 crossOverlays ? []
35
36, # A function booting the final package set for a specific standard
37 # environment. See below for the arguments given to that function, the type of
38 # list it returns.
39 stdenvStages ? import ../stdenv
40
41, # Ignore unexpected args.
42 ...
43} @ args:
44
45let # Rename the function arguments
46 config0 = config;
47 crossSystem0 = crossSystem;
48
49in let
50 lib = import ../../lib;
51
52 localSystem = lib.systems.elaborate args.localSystem;
53
54 # Condition preserves sharing which in turn affects equality.
55 crossSystem =
56 if crossSystem0 == null || crossSystem0 == args.localSystem
57 then localSystem
58 else lib.systems.elaborate crossSystem0;
59
60 # Allow both:
61 # { /* the config */ } and
62 # { pkgs, ... } : { /* the config */ }
63 config1 =
64 if lib.isFunction config0
65 then config0 { inherit pkgs; }
66 else config0;
67
68 configEval = lib.evalModules {
69 modules = [
70 ./config.nix
71 ({ options, ... }: {
72 _file = "nixpkgs.config";
73 # filter-out known options, FIXME: remove this eventually
74 config = builtins.intersectAttrs options config1;
75 })
76 ];
77 };
78
79 # take all the rest as-is
80 config = lib.showWarnings configEval.config.warnings
81 (config1 // builtins.removeAttrs configEval.config [ "_module" ]);
82
83 # A few packages make a new package set to draw their dependencies from.
84 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than
85 # give `all-packages.nix` all the arguments to this function, even ones that
86 # don't concern it, we give it this function to "re-call" nixpkgs, inheriting
87 # whatever arguments it doesn't explicitly provide. This way,
88 # `all-packages.nix` doesn't know more than it needs too.
89 #
90 # It's OK that `args` doesn't include default arguments from this file:
91 # they'll be deterministically inferred. In fact we must *not* include them,
92 # because it's important that if some parameter which affects the default is
93 # substituted with a different argument, the default is re-inferred.
94 #
95 # To put this in concrete terms, this function is basically just used today to
96 # use package for a different platform for the current platform (namely cross
97 # compiling toolchains and 32-bit packages on x86_64). In both those cases we
98 # want the provided non-native `localSystem` argument to affect the stdenv
99 # chosen.
100 #
101 # NB!!! This thing gets its `config` argument from `args`, i.e. it's actually
102 # `config0`. It is important to keep it to `config0` format (as opposed to the
103 # result of `evalModules`, i.e. the `config` variable above) throughout all
104 # nixpkgs evaluations since the above function `config0 -> config` implemented
105 # via `evalModules` is not idempotent. In other words, if you add `config` to
106 # `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from
107 # experience here.)
108 nixpkgsFun = newArgs: import ./. (args // newArgs);
109
110 # Partially apply some arguments for building bootstraping stage pkgs
111 # sets. Only apply arguments which no stdenv would want to override.
112 allPackages = newArgs: import ./stage.nix ({
113 inherit lib nixpkgsFun;
114 } // newArgs);
115
116 boot = import ../stdenv/booter.nix { inherit lib allPackages; };
117
118 stages = stdenvStages {
119 inherit lib localSystem crossSystem config overlays crossOverlays;
120 };
121
122 pkgs = boot stages;
123
124in pkgs