at 18.03-beta 99 lines 3.7 kB view raw
1/* This function composes the Nix Packages collection. It: 2 3 1. Applies the final stage to the given `config` if it is a function 4 5 2. Infers an appropriate `platform` based on the `system` if none is 6 provided 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{ # The system packages will be built on. See the manual for the 21 # subtle division of labor between these two `*System`s and the three 22 # `*Platform`s. 23 localSystem 24 25 # The system packages will ultimately be run on. Null if the two should be the 26 # same. 27, crossSystem ? null 28 29, # Allow a configuration attribute set to be passed in as an argument. 30 config ? {} 31 32, # List of overlays layers used to extend Nixpkgs. 33 overlays ? [] 34 35, # A function booting the final package set for a specific standard 36 # environment. See below for the arguments given to that function, the type of 37 # list it returns. 38 stdenvStages ? import ../stdenv 39} @ args: 40 41let # Rename the function arguments 42 configExpr = config; 43 crossSystem0 = crossSystem; 44 45in let 46 lib = import ../../lib; 47 48 # Allow both: 49 # { /* the config */ } and 50 # { pkgs, ... } : { /* the config */ } 51 config = 52 if lib.isFunction configExpr 53 then configExpr { inherit pkgs; } 54 else configExpr; 55 56 # From a minimum of `system` or `config` (actually a target triple, *not* 57 # nixpkgs configuration), infer the other one and platform as needed. 58 localSystem = lib.systems.elaborate ( 59 # Allow setting the platform in the config file. This take precedence over 60 # the inferred platform, but not over an explicitly passed-in one. 61 builtins.intersectAttrs { platform = null; } config 62 // args.localSystem); 63 64 crossSystem = lib.mapNullable lib.systems.elaborate crossSystem0; 65 66 # A few packages make a new package set to draw their dependencies from. 67 # (Currently to get a cross tool chain, or forced-i686 package.) Rather than 68 # give `all-packages.nix` all the arguments to this function, even ones that 69 # don't concern it, we give it this function to "re-call" nixpkgs, inheriting 70 # whatever arguments it doesn't explicitly provide. This way, 71 # `all-packages.nix` doesn't know more than it needs too. 72 # 73 # It's OK that `args` doesn't include default arguemtns from this file: 74 # they'll be deterministically inferred. In fact we must *not* include them, 75 # because it's important that if some parameter which affects the default is 76 # substituted with a different argument, the default is re-inferred. 77 # 78 # To put this in concrete terms, this function is basically just used today to 79 # use package for a different platform for the current platform (namely cross 80 # compiling toolchains and 32-bit packages on x86_64). In both those cases we 81 # want the provided non-native `localSystem` argument to affect the stdenv 82 # chosen. 83 nixpkgsFun = newArgs: import ./. (args // newArgs); 84 85 # Partially apply some arguments for building bootstraping stage pkgs 86 # sets. Only apply arguments which no stdenv would want to override. 87 allPackages = newArgs: import ./stage.nix ({ 88 inherit lib nixpkgsFun; 89 } // newArgs); 90 91 boot = import ../stdenv/booter.nix { inherit lib allPackages; }; 92 93 stages = stdenvStages { 94 inherit lib localSystem crossSystem config overlays; 95 }; 96 97 pkgs = boot stages; 98 99in pkgs