at 23.11-beta 144 lines 5.3 kB view raw
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 inherit (lib) throwIfNot; 53 54 checked = 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 59 ; 60 61 localSystem = lib.systems.elaborate args.localSystem; 62 63 # Condition preserves sharing which in turn affects equality. 64 # 65 # See `lib.systems.equals` documentation for more details. 66 # 67 # Note that it is generally not possible to compare systems as given in 68 # parameters, e.g. if systems are initialized as 69 # 70 # localSystem = { system = "x86_64-linux"; }; 71 # crossSystem = { config = "x86_64-unknown-linux-gnu"; }; 72 # 73 # Both systems are semantically equivalent as the same vendor and ABI are 74 # inferred from the system double in `localSystem`. 75 crossSystem = 76 let system = lib.systems.elaborate crossSystem0; in 77 if crossSystem0 == null || lib.systems.equals system localSystem 78 then localSystem 79 else system; 80 81 # Allow both: 82 # { /* the config */ } and 83 # { pkgs, ... } : { /* the config */ } 84 config1 = 85 if lib.isFunction config0 86 then config0 { inherit pkgs; } 87 else config0; 88 89 configEval = lib.evalModules { 90 modules = [ 91 ./config.nix 92 ({ options, ... }: { 93 _file = "nixpkgs.config"; 94 config = config1; 95 }) 96 ]; 97 class = "nixpkgsConfig"; 98 }; 99 100 # take all the rest as-is 101 config = lib.showWarnings configEval.config.warnings configEval.config; 102 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. 109 # 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. 114 # 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 119 # chosen. 120 # 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 127 # experience here.) 128 nixpkgsFun = newArgs: import ./. (args // newArgs); 129 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; 134 } // newArgs); 135 136 boot = import ../stdenv/booter.nix { inherit lib allPackages; }; 137 138 stages = stdenvStages { 139 inherit lib localSystem crossSystem config overlays crossOverlays; 140 }; 141 142 pkgs = boot stages; 143 144in checked pkgs