···3030<itemizedlist>
3131 <listitem>
3232 <para>
3333+ <literal>stdenv.overrides</literal> is now expected to take <literal>self</literal>
3434+ and <literal>super</literal> arguments. See <literal>lib.trivial.extends</literal>
3535+ for what those parameters represent.
3636+ </para>
3737+ </listitem>
3838+3939+ <listitem>
4040+ <para>
3341 <literal>gnome</literal> alias has been removed along with
3442 <literal>gtk</literal>, <literal>gtkmm</literal> and several others.
3543 Now you need to use versioned attributes, like <literal>gnome3</literal>.
+68
pkgs/stdenv/booter.nix
···11+# This file defines a single function for booting a package set from a list of
22+# stages. The exact mechanics of that function are defined below; here I
33+# (@Ericson2314) wish to describe the purpose of the abstraction.
44+#
55+# The first goal is consistency across stdenvs. Regardless of what this function
66+# does, by making every stdenv use it for bootstrapping we ensure that they all
77+# work in a similar way. [Before this abstraction, each stdenv was its own
88+# special snowflake due to different authors writing in different times.]
99+#
1010+# The second goal is consistency across each stdenv's stage functions. By
1111+# writing each stage it terms of the previous stage, commonalities between them
1212+# are more easily observable. [Before, there usually was a big attribute set
1313+# with each stage, and stages would access the previous stage by name.]
1414+#
1515+# The third goal is composition. Because each stage is written in terms of the
1616+# previous, the list can be reordered or, more practically, extended with new
1717+# stages. The latter is used for cross compiling and custom
1818+# stdenvs. Additionally, certain options should by default apply only to the
1919+# last stage, whatever it may be. By delaying the creation of stage package sets
2020+# until the final fold, we prevent these options from inhibiting composition.
2121+#
2222+# The fourth and final goal is debugging. Normal packages should only source
2323+# their dependencies from the current stage. But for the sake of debugging, it
2424+# is nice that all packages still remain accessible. We make sure previous
2525+# stages are kept around with a `stdenv.__bootPackges` attribute referring the
2626+# previous stage. It is idiomatic that attributes prefixed with `__` come with
2727+# special restrictions and should not be used under normal circumstances.
2828+{ lib, allPackages }:
2929+3030+# Type:
3131+# [ pkgset -> (args to stage/default.nix) or ({ __raw = true; } // pkgs) ]
3232+# -> pkgset
3333+#
3434+# In english: This takes a list of function from the previous stage pkgset and
3535+# returns the final pkgset. Each of those functions returns, if `__raw` is
3636+# undefined or false, args for this stage's pkgset (the most complex and
3737+# important arg is the stdenv), or, if `__raw = true`, simply this stage's
3838+# pkgset itself.
3939+#
4040+# The list takes stages in order, so the final stage is last in the list. In
4141+# other words, this does a foldr not foldl.
4242+stageFuns: let
4343+4444+ # Take the list and disallow custom overrides in all but the final stage,
4545+ # and allow it in the final flag. Only defaults this boolean field if it
4646+ # isn't already set.
4747+ withAllowCustomOverrides = lib.lists.imap
4848+ (index: stageFun: prevStage:
4949+ # So true by default for only the first element because one
5050+ # 1-indexing. Since we reverse the list, this means this is true
5151+ # for the final stage.
5252+ { allowCustomOverrides = index == 1; }
5353+ // (stageFun prevStage))
5454+ (lib.lists.reverseList stageFuns);
5555+5656+ # Adds the stdenv to the arguments, and sticks in it the previous stage for
5757+ # debugging purposes.
5858+ folder = stageFun: finalSoFar: let
5959+ args = stageFun finalSoFar;
6060+ stdenv = args.stdenv // {
6161+ # For debugging
6262+ __bootPackages = finalSoFar;
6363+ };
6464+ args' = args // { inherit stdenv; };
6565+ in
6666+ (if args.__raw or false then lib.id else allPackages) args';
6767+6868+in lib.lists.fold folder {} withAllowCustomOverrides
+35-21
pkgs/stdenv/cross/default.nix
···11-{ lib, allPackages
11+{ lib
22, system, platform, crossSystem, config
33}:
4455-rec {
66- vanillaStdenv = (import ../. {
77- inherit lib allPackages system platform;
55+let
66+ bootStages = import ../. {
77+ inherit lib system platform;
88 crossSystem = null;
99 # Ignore custom stdenvs when cross compiling for compatability
1010 config = builtins.removeAttrs config [ "replaceStdenv" ];
1111- }) // {
1212- # Needed elsewhere as a hacky way to pass the target
1313- cross = crossSystem;
1411 };
15121616- # For now, this is just used to build the native stdenv. Eventually, it should
1717- # be used to build compilers and other such tools targeting the cross
1313+in bootStages ++ [
1414+1515+ # Build Packages.
1616+ #
1717+ # For now, this is just used to build the native stdenv. Eventually, it
1818+ # should be used to build compilers and other such tools targeting the cross
1819 # platform. Then, `forceNativeDrv` can be removed.
1919- buildPackages = allPackages {
2020+ (vanillaPackages: {
2021 inherit system platform crossSystem config;
2122 # It's OK to change the built-time dependencies
2223 allowCustomOverrides = true;
2323- stdenv = vanillaStdenv;
2424- };
2424+ stdenv = vanillaPackages.stdenv // {
2525+ # Needed elsewhere as a hacky way to pass the target
2626+ cross = crossSystem;
2727+ overrides = _: _: {};
2828+ };
2929+ })
25302626- stdenvCross = buildPackages.makeStdenvCross
2727- buildPackages.stdenv crossSystem
2828- buildPackages.binutilsCross buildPackages.gccCrossStageFinal;
3131+ # Run packages
3232+ (buildPackages: {
3333+ inherit system platform crossSystem config;
3434+ stdenv = if crossSystem.useiOSCross or false
3535+ then let
3636+ inherit (buildPackages.darwin.ios-cross {
3737+ prefix = crossSystem.config;
3838+ inherit (crossSystem) arch;
3939+ simulator = crossSystem.isiPhoneSimulator or false; })
4040+ cc binutils;
4141+ in buildPackages.makeStdenvCross
4242+ buildPackages.stdenv crossSystem
4343+ binutils cc
4444+ else buildPackages.makeStdenvCross
4545+ buildPackages.stdenv crossSystem
4646+ buildPackages.binutilsCross buildPackages.gccCrossStageFinal;
4747+ })
29483030- stdenvCrossiOS = let
3131- inherit (buildPackages.darwin.ios-cross { prefix = crossSystem.config; inherit (crossSystem) arch; simulator = crossSystem.isiPhoneSimulator or false; }) cc binutils;
3232- in buildPackages.makeStdenvCross
3333- buildPackages.stdenv crossSystem
3434- binutils cc;
3535-}
4949+]
···334334 # The ultimate test: bootstrap a whole stdenv from the tools specified above and get a package set out of it
335335 test-pkgs = import test-pkgspath {
336336 inherit system;
337337- stdenvFunc = args: let
337337+ stdenvStages = args: let
338338 args' = args // { inherit bootstrapFiles; };
339339- in (import (test-pkgspath + "/pkgs/stdenv/darwin") args').stdenvDarwin;
339339+ in (import (test-pkgspath + "/pkgs/stdenv/darwin") args').stagesDarwin;
340340 };
341341}
+33-45
pkgs/stdenv/default.nix
···11-# This file defines the various standard build environments.
11+# This file chooses a sane default stdenv given the system, platform, etc.
22#
33-# On Linux systems, the standard build environment consists of
44-# Nix-built instances glibc and the `standard' Unix tools, i.e., the
55-# Posix utilities, the GNU C compiler, and so on. On other systems,
66-# we use the native C library.
33+# Rather than returning a stdenv, this returns a list of functions---one per
44+# each bootstrapping stage. See `./booter.nix` for exactly what this list should
55+# contain.
7687{ # Args just for stdenvs' usage
99- lib, allPackages
1010- # Args to pass on to `allPacakges` too
88+ lib
99+ # Args to pass on to the pkgset builder, too
1110, system, platform, crossSystem, config
1211} @ args:
1312···1716 # i.e., the stuff in /bin, /usr/bin, etc. This environment should
1817 # be used with care, since many Nix packages will not build properly
1918 # with it (e.g., because they require GNU Make).
2020- inherit (import ./native args) stdenvNative;
2121-2222- stdenvNativePkgs = allPackages {
2323- inherit system platform crossSystem config;
2424- allowCustomOverrides = false;
2525- stdenv = stdenvNative;
2626- noSysDirs = false;
2727- };
2828-1919+ stagesNative = import ./native args;
29203021 # The Nix build environment.
3131- stdenvNix = assert crossSystem == null; import ./nix {
3232- inherit config lib;
3333- stdenv = stdenvNative;
3434- pkgs = stdenvNativePkgs;
3535- };
2222+ stagesNix = import ./nix (args // { bootStages = stagesNative; });
36233737- inherit (import ./freebsd args) stdenvFreeBSD;
2424+ stagesFreeBSD = import ./freebsd args;
38253939- # Linux standard environment.
4040- inherit (import ./linux args) stdenvLinux;
2626+ # On Linux systems, the standard build environment consists of Nix-built
2727+ # instances glibc and the `standard' Unix tools, i.e., the Posix utilities,
2828+ # the GNU C compiler, and so on.
2929+ stagesLinux = import ./linux args;
41304242- inherit (import ./darwin args) stdenvDarwin;
3131+ inherit (import ./darwin args) stagesDarwin;
43324444- inherit (import ./cross args) stdenvCross stdenvCrossiOS;
3333+ stagesCross = import ./cross args;
45344646- inherit (import ./custom args) stdenvCustom;
3535+ stagesCustom = import ./custom args;
47364848- # Select the appropriate stdenv for the platform `system'.
3737+ # Select the appropriate stages for the platform `system'.
4938in
5050- if crossSystem != null then
5151- if crossSystem.useiOSCross or false then stdenvCrossiOS
5252- else stdenvCross else
5353- if config ? replaceStdenv then stdenvCustom else
5454- if system == "i686-linux" then stdenvLinux else
5555- if system == "x86_64-linux" then stdenvLinux else
5656- if system == "armv5tel-linux" then stdenvLinux else
5757- if system == "armv6l-linux" then stdenvLinux else
5858- if system == "armv7l-linux" then stdenvLinux else
5959- if system == "mips64el-linux" then stdenvLinux else
6060- if system == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
6161- if system == "x86_64-darwin" then stdenvDarwin else
6262- if system == "x86_64-solaris" then stdenvNix else
6363- if system == "i686-cygwin" then stdenvNative else
6464- if system == "x86_64-cygwin" then stdenvNative else
6565- if system == "x86_64-freebsd" then stdenvFreeBSD else
6666- stdenvNative
3939+ if crossSystem != null then stagesCross
4040+ else if config ? replaceStdenv then stagesCustom
4141+ else { # switch
4242+ "i686-linux" = stagesLinux;
4343+ "x86_64-linux" = stagesLinux;
4444+ "armv5tel-linux" = stagesLinux;
4545+ "armv6l-linux" = stagesLinux;
4646+ "armv7l-linux" = stagesLinux;
4747+ "mips64el-linux" = stagesLinux;
4848+ "powerpc-linux" = /* stagesLinux */ stagesNative;
4949+ "x86_64-darwin" = stagesDarwin;
5050+ "x86_64-solaris" = stagesNix;
5151+ "i686-cygwin" = stagesNative;
5252+ "x86_64-cygwin" = stagesNative;
5353+ "x86_64-freebsd" = stagesFreeBSD;
5454+ }.${system} or stagesNative
···55 * to merges. Please use the full-text search of your editor. ;)
66 * Hint: ### starts category names.
77 */
88-{ system, noSysDirs, config, crossSystem, platform, lib
99-, nixpkgsFun
1010-}:
88+{ lib, nixpkgsFun, noSysDirs, config}:
119self: pkgs:
12101311with pkgs;
···1715in
18161917{
2020-2121- # Make some arguments passed to all-packages.nix available
2222- inherit system platform;
23182419 # Allow callPackage to fill in the pkgs argument
2520 inherit pkgs;
···47284723 gambit = callPackage ../development/compilers/gambit { };
4729472447304725 gcc = gcc5;
47264726+ gcc-unwrapped = gcc.cc;
4731472747324728 wrapCCMulti = cc:
47334729 if system == "x86_64-linux" then lowPrio (
+13-10
pkgs/top-level/default.nix
···7788 3. Defaults to no non-standard config and no cross-compilation target
991010- 4. Uses the above to infer the default standard environment (stdenv) if
1111- none is provided
1010+ 4. Uses the above to infer the default standard environment's (stdenv's)
1111+ stages if no stdenv's are provided
12121313- 5. Builds the final stage --- a fully booted package set with the chosen
1414- stdenv
1313+ 5. Folds the stages to yield the final fully booted package set for the
1414+ chosen stdenv
15151616 Use `impure.nix` to also infer the `system` based on the one on which
1717 evaluation is taking place, and the configuration from environment variables
···2323, # Allow a configuration attribute set to be passed in as an argument.
2424 config ? {}
25252626-, # The standard environment for building packages, or rather a function
2727- # providing it. See below for the arguments given to that function.
2828- stdenvFunc ? import ../stdenv
2626+, # A function booting the final package set for a specific standard
2727+ # environment. See below for the arguments given to that function,
2828+ # the type of list it returns.
2929+ stdenvStages ? import ../stdenv
29303031, crossSystem ? null
3132, platform ? assert false; null
···7677 inherit lib nixpkgsFun;
7778 } // newArgs);
78797979- stdenv = stdenvFunc {
8080- inherit lib allPackages system platform crossSystem config;
8080+ boot = import ../stdenv/booter.nix { inherit lib allPackages; };
8181+8282+ stages = stdenvStages {
8383+ inherit lib system platform crossSystem config;
8184 };
82858383- pkgs = allPackages { inherit system stdenv config crossSystem platform; };
8686+ pkgs = boot stages;
84878588in pkgs
+12-14
pkgs/top-level/stage.nix
···1818, # This is used because stdenv replacement and the stdenvCross do benefit from
1919 # the overridden configuration provided by the user, as opposed to the normal
2020 # bootstrapping stdenvs.
2121- allowCustomOverrides ? true
2121+ allowCustomOverrides
22222323, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
2424 # outside of the store. Thus, GCC, GFortran, & co. must always look for
···4747 inherit lib; inherit (self) stdenv stdenvNoCC; inherit (self.xorg) lndir;
4848 };
49495050- stdenvDefault = self: super:
5151- { stdenv = stdenv // { inherit platform; }; };
5050+ stdenvBootstappingAndPlatforms = self: super: {
5151+ stdenv = stdenv // { inherit platform; };
5252+ inherit
5353+ system platform crossSystem;
5454+ };
52555356 allPackages = self: super:
5457 let res = import ./all-packages.nix
5555- { inherit system noSysDirs config crossSystem platform lib nixpkgsFun; }
5858+ { inherit lib nixpkgsFun noSysDirs config; }
5659 res self;
5760 in res;
58615962 aliases = self: super: import ./aliases.nix super;
60636161- # stdenvOverrides is used to avoid circular dependencies for building
6262- # the standard build environment. This mechanism uses the override
6363- # mechanism to implement some staged compilation of the stdenv.
6464- #
6565- # We don't want stdenv overrides in the case of cross-building, or
6666- # otherwise the basic overridden packages will not be built with the
6767- # crossStdenv adapter.
6464+ # stdenvOverrides is used to avoid having multiple of versions
6565+ # of certain dependencies that were used in bootstrapping the
6666+ # standard environment.
6867 stdenvOverrides = self: super:
6969- lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
7070- (super.stdenv.overrides super);
6868+ (super.stdenv.overrides or (_: _: {})) self super;
71697270 # Allow packages to be overridden globally via the `packageOverrides'
7371 # configuration option, which must be a function that takes `pkgs'
···82808381 # The complete chain of package set builders, applied from top to bottom
8482 toFix = lib.foldl' (lib.flip lib.extends) (self: {}) [
8585- stdenvDefault
8383+ stdenvBootstappingAndPlatforms
8684 stdenvAdapters
8785 trivialBuilders
8886 allPackages