nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at haskell-updates 220 lines 7.6 kB view raw
1/* 2 This function composes the Nix Packages collection. It: 3 4 1. Elaborates `localSystem` and `crossSystem` with defaults as needed. 5 6 2. Applies the final stage to the given `config` if it is a function 7 8 3. Defaults to no non-standard config and no cross-compilation target 9 10 4. Uses the above to infer the default standard environment's (stdenv's) 11 stages if no stdenv's are provided 12 13 5. Folds the stages to yield the final fully booted package set for the 14 chosen stdenv 15 16 Use `impure.nix` to also infer the `system` based on the one on which 17 evaluation is taking place, and the configuration from environment variables 18 or dot-files. 19*/ 20 21let 22 # We hoist this above the closure so that the same thunk is shared 23 # between multiple imports of Nixpkgs. This ensures that commands 24 # like `nix eval nixpkgs#legacyPackages.x86_64-darwin.pkgsStatic.hello` 25 # print only one warning, which would otherwise be spammy in common 26 # scenarios that instantiate many copies of Nixpkgs. 27 # 28 # Unfortunately, flakes’ handling of transitive dependencies mean 29 # that it’s still likely users will see multiple warnings, but 30 # there’s nothing we can do about that within the constraints of the 31 # Nix language. 32 x86_64DarwinDeprecationWarning = 33 pristineLib.warn 34 "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" 35 (x: x); 36 37 pristineLib = import ../../lib; 38in 39 40{ 41 # The system packages will be built on. See the manual for the 42 # subtle division of labor between these two `*System`s and the three 43 # `*Platform`s. 44 localSystem, 45 46 # The system packages will ultimately be run on. 47 crossSystem ? localSystem, 48 49 # Allow a configuration attribute set to be passed in as an argument. 50 config ? { }, 51 52 # Temporary hack to let Nixpkgs forbid internal use of `lib.fileset` 53 # until <https://github.com/NixOS/nix/issues/11503> is fixed. 54 __allowFileset ? true, 55 56 # List of overlays layers used to extend Nixpkgs. 57 overlays ? [ ], 58 59 # List of overlays to apply to target packages only. 60 crossOverlays ? [ ], 61 62 # A function booting the final package set for a specific standard 63 # environment. See below for the arguments given to that function, the type of 64 # list it returns. 65 stdenvStages ? import ../stdenv, 66 67 # Ignore unexpected args. 68 ... 69}@args: 70 71let # Rename the function arguments 72 config0 = config; 73 crossSystem0 = crossSystem; 74 75in 76let 77 lib = 78 if __allowFileset then 79 pristineLib 80 else 81 pristineLib.extend ( 82 _: _: { 83 fileset = abort '' 84 85 The use of `lib.fileset` is currently forbidden in Nixpkgs due to the 86 upstream Nix bug <https://github.com/NixOS/nix/issues/11503>. This 87 causes difficulttodebug errors when combined with chroot stores, 88 such as in the NixOS installer. 89 90 For packages that require source to be vendored inside Nixpkgs, 91 please use a subdirectory of the package instead. 92 ''; 93 } 94 ); 95 96 inherit (lib) throwIfNot; 97 98 checked = 99 (throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list.") 100 (throwIfNot (lib.all lib.isFunction overlays) "All overlays passed to nixpkgs must be functions.") 101 (throwIfNot (lib.isList crossOverlays) "The crossOverlays argument to nixpkgs must be a list.") 102 (throwIfNot (lib.all lib.isFunction crossOverlays) "All crossOverlays passed to nixpkgs must be functions.") 103 ( 104 if 105 ( 106 ((localSystem.isDarwin && localSystem.isx86) || (crossSystem.isDarwin && crossSystem.isx86)) 107 && config.allowDeprecatedx86_64Darwin == false 108 ) 109 then 110 x86_64DarwinDeprecationWarning 111 else 112 x: x 113 ); 114 115 localSystem = lib.systems.elaborate args.localSystem; 116 117 # Condition preserves sharing which in turn affects equality. 118 # 119 # See `lib.systems.equals` documentation for more details. 120 # 121 # Note that it is generally not possible to compare systems as given in 122 # parameters, e.g. if systems are initialized as 123 # 124 # localSystem = { system = "x86_64-linux"; }; 125 # crossSystem = { config = "x86_64-unknown-linux-gnu"; }; 126 # 127 # Both systems are semantically equivalent as the same vendor and ABI are 128 # inferred from the system double in `localSystem`. 129 crossSystem = 130 let 131 system = lib.systems.elaborate crossSystem0; 132 in 133 if crossSystem0 == null || lib.systems.equals system localSystem then localSystem else system; 134 135 # Allow both: 136 # { /* the config */ } and 137 # { pkgs, ... } : { /* the config */ } 138 config1 = if lib.isFunction config0 then config0 { inherit lib pkgs; } else config0; 139 140 configEval = lib.evalModules { 141 modules = [ 142 ./config.nix 143 ( 144 { options, ... }: 145 { 146 _file = "nixpkgs.config"; 147 config = config1; 148 } 149 ) 150 ]; 151 class = "nixpkgsConfig"; 152 }; 153 154 # take all the rest as-is 155 config = 156 let 157 failedAssertionsString = lib.concatMapStringsSep "\n" (x: "- ${x.message}") ( 158 lib.filter (x: !x.assertion) configEval.config.assertions 159 ); 160 in 161 if failedAssertionsString != "" then 162 throw "Failed assertions:\n${failedAssertionsString}" 163 else 164 lib.showWarnings configEval.config.warnings configEval.config; 165 166 # A few packages make a new package set to draw their dependencies from. 167 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than 168 # give `all-packages.nix` all the arguments to this function, even ones that 169 # don't concern it, we give it this function to "re-call" nixpkgs, inheriting 170 # whatever arguments it doesn't explicitly provide. This way, 171 # `all-packages.nix` doesn't know more than it needs too. 172 # 173 # It's OK that `args` doesn't include default arguments from this file: 174 # they'll be deterministically inferred. In fact we must *not* include them, 175 # because it's important that if some parameter which affects the default is 176 # substituted with a different argument, the default is re-inferred. 177 # 178 # To put this in concrete terms, this function is basically just used today to 179 # use package for a different platform for the current platform (namely cross 180 # compiling toolchains and 32-bit packages on x86_64). In both those cases we 181 # want the provided non-native `localSystem` argument to affect the stdenv 182 # chosen. 183 # 184 # NB!!! This thing gets its `config` argument from `args`, i.e. it's actually 185 # `config0`. It is important to keep it to `config0` format (as opposed to the 186 # result of `evalModules`, i.e. the `config` variable above) throughout all 187 # nixpkgs evaluations since the above function `config0 -> config` implemented 188 # via `evalModules` is not idempotent. In other words, if you add `config` to 189 # `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from 190 # experience here.) 191 nixpkgsFun = newArgs: import ./. (args // newArgs); 192 193 # Partially apply some arguments for building bootstrapping stage pkgs 194 # sets. Only apply arguments which no stdenv would want to override. 195 allPackages = 196 newArgs: 197 import ./stage.nix ( 198 { 199 inherit lib nixpkgsFun; 200 } 201 // newArgs 202 ); 203 204 boot = import ../stdenv/booter.nix { inherit lib allPackages; }; 205 206 stages = stdenvStages { 207 inherit 208 lib 209 localSystem 210 crossSystem 211 config 212 overlays 213 crossOverlays 214 ; 215 }; 216 217 pkgs = boot stages; 218 219in 220checked pkgs