1 /* This function composes the Nix Packages collection. It:
3 1. Elaborates `localSystem` and `crossSystem` with defaults as needed.
5 2. Applies the final stage to the given `config` if it is a function
7 3. Defaults to no non-standard config and no cross-compilation target
9 4. Uses the above to infer the default standard environment's (stdenv's)
10 stages if no stdenv's are provided
12 5. Folds the stages to yield the final fully booted package set for the
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
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
24 , # The system packages will ultimately be run on.
25 crossSystem ? localSystem
27 , # Allow a configuration attribute set to be passed in as an argument.
30 , # List of overlays layers used to extend Nixpkgs.
33 , # List of overlays to apply to target packages only.
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
39 stdenvStages ? import ../stdenv
41 , # Ignore unexpected args.
45 let # Rename the function arguments
47 crossSystem0 = crossSystem;
50 lib = import ../../lib;
52 inherit (lib) throwIfNot;
55 throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list."
56 lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays
57 throwIfNot (lib.isList crossOverlays) "The crossOverlays argument to nixpkgs must be a list."
58 lib.foldr (x: throwIfNot (lib.isFunction x) "All crossOverlays passed to nixpkgs must be functions.") (r: r) crossOverlays
61 localSystem = lib.systems.elaborate args.localSystem;
63 # Condition preserves sharing which in turn affects equality.
65 # See `lib.systems.equals` documentation for more details.
67 # Note that it is generally not possible to compare systems as given in
68 # parameters, e.g. if systems are initialized as
70 # localSystem = { system = "x86_64-linux"; };
71 # crossSystem = { config = "x86_64-unknown-linux-gnu"; };
73 # Both systems are semantically equivalent as the same vendor and ABI are
74 # inferred from the system double in `localSystem`.
76 let system = lib.systems.elaborate crossSystem0; in
77 if crossSystem0 == null || lib.systems.equals system localSystem
82 # { /* the config */ } and
83 # { pkgs, ... } : { /* the config */ }
85 if lib.isFunction config0
86 then config0 { inherit pkgs; }
89 configEval = lib.evalModules {
93 _file = "nixpkgs.config";
97 class = "nixpkgsConfig";
100 # take all the rest as-is
101 config = lib.showWarnings configEval.config.warnings configEval.config;
103 # A few packages make a new package set to draw their dependencies from.
104 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than
105 # give `all-packages.nix` all the arguments to this function, even ones that
106 # don't concern it, we give it this function to "re-call" nixpkgs, inheriting
107 # whatever arguments it doesn't explicitly provide. This way,
108 # `all-packages.nix` doesn't know more than it needs too.
110 # It's OK that `args` doesn't include default arguments from this file:
111 # they'll be deterministically inferred. In fact we must *not* include them,
112 # because it's important that if some parameter which affects the default is
113 # substituted with a different argument, the default is re-inferred.
115 # To put this in concrete terms, this function is basically just used today to
116 # use package for a different platform for the current platform (namely cross
117 # compiling toolchains and 32-bit packages on x86_64). In both those cases we
118 # want the provided non-native `localSystem` argument to affect the stdenv
121 # NB!!! This thing gets its `config` argument from `args`, i.e. it's actually
122 # `config0`. It is important to keep it to `config0` format (as opposed to the
123 # result of `evalModules`, i.e. the `config` variable above) throughout all
124 # nixpkgs evaluations since the above function `config0 -> config` implemented
125 # via `evalModules` is not idempotent. In other words, if you add `config` to
126 # `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from
128 nixpkgsFun = newArgs: import ./. (args // newArgs);
130 # Partially apply some arguments for building bootstraping stage pkgs
131 # sets. Only apply arguments which no stdenv would want to override.
132 allPackages = newArgs: import ./stage.nix ({
133 inherit lib nixpkgsFun;
136 boot = import ../stdenv/booter.nix { inherit lib allPackages; };
138 stages = stdenvStages {
139 inherit lib localSystem crossSystem config overlays crossOverlays;