From d240a0da1ab03ef8838553229b72b9b37a0ef3e7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 27 Nov 2016 12:35:58 -0800 Subject: [PATCH] top-level: Remove cycles: stdenv calls in top-level but not vice versa This commit changes the dependencies of stdenv, and clean-up the stdenv story by removing the `defaultStdenv` attribute as well as the `bootStdenv` parameter. Before, the final bootstrapping stage's stdenv was provided by all-packages, which was iterating multiple times over the top-level/default.nix expression, and non-final bootstrapping stages' stdenvs were explicitly specified with the `bootStdenv` parameter. Now, all stages' stdenvs are specified with the `stdenv` parameter. For non-final bootstrapping stages, this is a small change---basically just rename the parameter. For the final stage, top-level/default.nix takes the chosen stdenv and makes the final stage with it. `allPackages` is used to make all bootstrapping stages, final and non-final alike. It's basically the expression of `stage.nix` (along with a few partially-applied default arguments) Note, the make-bootstrap-tools scripts are temporarily broken --- pkgs/stdenv/cross/default.nix | 2 +- pkgs/stdenv/custom/default.nix | 2 +- pkgs/stdenv/darwin/default.nix | 5 +++-- pkgs/stdenv/default.nix | 5 +++-- pkgs/stdenv/freebsd/default.nix | 2 +- pkgs/stdenv/linux/default.nix | 3 ++- pkgs/stdenv/native/default.nix | 3 ++- pkgs/top-level/default.nix | 37 +++++++++++++++++++++++++-------- pkgs/top-level/stage.nix | 27 ++++++++++++------------ pkgs/top-level/stdenv.nix | 13 ------------ 10 files changed, 55 insertions(+), 44 deletions(-) delete mode 100644 pkgs/top-level/stdenv.nix diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index e48124f1c4db..fcf06bcf1daf 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -20,7 +20,7 @@ rec { inherit system platform crossSystem config; # It's OK to change the built-time dependencies allowCustomOverrides = true; - bootStdenv = vanillaStdenv; + stdenv = vanillaStdenv; }; stdenvCross = buildPackages.makeStdenvCross diff --git a/pkgs/stdenv/custom/default.nix b/pkgs/stdenv/custom/default.nix index 4c14d6411f10..e8f203d69cf8 100644 --- a/pkgs/stdenv/custom/default.nix +++ b/pkgs/stdenv/custom/default.nix @@ -10,7 +10,7 @@ rec { inherit system platform crossSystem config; # It's OK to change the built-time dependencies allowCustomOverrides = true; - bootStdenv = vanillaStdenv; + stdenv = vanillaStdenv; }; stdenvCustom = config.replaceStdenv { pkgs = buildPackages; }; diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 1bc983d63129..49c4d9b8b2bc 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -22,7 +22,7 @@ let (import "${./standard-sandbox.sb}") ''; in rec { - allPackages = import ../../..; + inherit allPackages; commonPreHook = '' export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}" @@ -101,7 +101,8 @@ in rec { thisPkgs = allPackages { inherit system platform; - bootStdenv = thisStdenv; + allowCustomOverrides = false; + stdenv = thisStdenv; }; in { stdenv = thisStdenv; pkgs = thisPkgs; }; diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index ac84ea0f9a0b..bd515181fc6e 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -5,7 +5,7 @@ # Posix utilities, the GNU C compiler, and so on. On other systems, # we use the native C library. -{ system, allPackages ? import ../.., platform, config, crossSystem, lib }: +{ system, allPackages ? import ../top-level, platform, config, crossSystem, lib }: let @@ -19,7 +19,8 @@ let inherit (import ./native { inherit system allPackages config; }) stdenvNative; stdenvNativePkgs = allPackages { - bootStdenv = stdenvNative; + allowCustomOverrides = false; + stdenv = stdenvNative; noSysDirs = false; }; diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index 4c7ebc16239b..13cb21fe1d88 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -5,7 +5,7 @@ }: rec { - allPackages = import ../../..; + inherit allPackages; bootstrapTools = derivation { inherit system; diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index e3aeafe178d3..e0a68bdca2f3 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -107,7 +107,8 @@ rec { thisPkgs = allPackages { inherit system platform; - bootStdenv = thisStdenv; + allowCustomOverrides = false; + stdenv = thisStdenv; }; in { stdenv = thisStdenv; pkgs = thisPkgs; }; diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index fcd0805275be..22b4dc1400fe 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -127,7 +127,8 @@ rec { stdenvBoot1Pkgs = allPackages { inherit system; - bootStdenv = stdenvBoot1; + allowCustomOverrides = false; + stdenv = stdenvBoot1; }; diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index c5b8bbac31c0..d1e824a8070b 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -1,8 +1,21 @@ -/* This file composes the Nix Packages collection. That is, it - imports the functions that build the various packages, and calls - them with appropriate arguments. The result is a set of all the - packages in the Nix Packages collection for some particular - platform. */ +/* This function composes the Nix Packages collection. It: + + 1. Applies the final stage to the given `config` if it is a function + + 2. Infers an appropriate `platform` based on the `system` if none is + provided + + 3. Defaults to no non-standard config and no cross-compilation target + + 4. Uses the above to infer the default standard environment (stdenv) if + none is provided + + 5. Builds the final stage --- a fully booted package set with the chosen + stdenv + + Use `impure.nix` to also infer the `system` based on the one on which + evaluation is taking place, and the configuration from environment variables + or dot-files. */ { # The system (e.g., `i686-linux') for which to build the packages. system @@ -12,7 +25,6 @@ , crossSystem ? null , platform ? null -, ... } @ args: let # Rename the function arguments @@ -57,8 +69,15 @@ in let # deterministically inferred the same way. nixpkgsFun = newArgs: import ./. (args // newArgs); - pkgs = import ./stage.nix ({ - inherit lib nixpkgsFun config platform; - } // args); + # Partially apply some args for building bootstraping stage pkgs sets + allPackages = newArgs: import ./stage.nix ({ + inherit lib nixpkgsFun config; + } // newArgs); + + stdenv = import ../stdenv { + inherit lib allPackages system platform crossSystem config; + }; + + pkgs = allPackages { inherit system stdenv config crossSystem platform; }; in pkgs diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 9ab9d22e54fe..0c621b81c7ed 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -1,21 +1,24 @@ -/* This file composes the Nix Packages collection. That is, it - imports the functions that build the various packages, and calls - them with appropriate arguments. The result is a set of all the - packages in the Nix Packages collection for some particular - platform. */ +/* This file composes a single bootstrapping stage of the Nix Packages + collection. That is, it imports the functions that build the various + packages, and calls them with appropriate arguments. The result is a set of + all the packages in the Nix Packages collection for some particular platform + for some particular stage. + + Default arguments are only provided for bootstrapping + arguments. Normal users should not import this directly but instead + import `pkgs/default.nix` or `default.nix`. */ { # The system (e.g., `i686-linux') for which to build the packages. system -, # The standard environment to use. Only used for bootstrapping. If - # null, the default standard environment is used. - bootStdenv ? null +, # The standard environment to use for building packages. + stdenv , # This is used because stdenv replacement and the stdenvCross do benefit from # the overridden configuration provided by the user, as opposed to the normal # bootstrapping stdenvs. - allowCustomOverrides ? (bootStdenv == null) + allowCustomOverrides ? true , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc # outside of the store. Thus, GCC, GFortran, & co. must always look for @@ -45,9 +48,7 @@ let }; stdenvDefault = self: super: - import ./stdenv.nix { - inherit system bootStdenv crossSystem config platform lib nixpkgsFun; - }; + { stdenv = stdenv // { inherit platform; }; }; allPackages = self: super: let res = import ./all-packages.nix @@ -81,9 +82,9 @@ let # The complete chain of package set builders, applied from top to bottom toFix = lib.foldl' (lib.flip lib.extends) (self: {}) [ + stdenvDefault stdenvAdapters trivialBuilders - stdenvDefault allPackages aliases stdenvOverrides diff --git a/pkgs/top-level/stdenv.nix b/pkgs/top-level/stdenv.nix deleted file mode 100644 index adb8bdde6ad0..000000000000 --- a/pkgs/top-level/stdenv.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ system, bootStdenv, crossSystem, config, platform, lib, nixpkgsFun }: - -rec { - defaultStdenv = import ../stdenv { - inherit system platform config crossSystem lib; - allPackages = nixpkgsFun; - } // { inherit platform; }; - - stdenv = - if bootStdenv != null - then (bootStdenv // { inherit platform; }) - else defaultStdenv; -}