summary refs log tree commit diff
path: root/pkgs/top-level
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@yahoo.com>2017-01-24 15:09:56 -0500
committerGitHub <noreply@github.com>2017-01-24 15:09:56 -0500
commit5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5 (patch)
treedd63532ca1ebe23b3c9480a660b00bc76967aae7 /pkgs/top-level
parent54df1426721358e21abcb7dc3a787e7df88ce122 (diff)
parent39fb46f5384bd4d28f1b10580ac9227c4ed36da2 (diff)
downloadnixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar.gz
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar.bz2
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar.lz
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar.xz
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.tar.zst
nixpkgs-5ad696b06763b7c5c6e1aa7ed848a50bff78c8d5.zip
Merge pull request #22107 from Ericson2314/cross-tepid
Somewhat saner cross-compiling through bootstrapping 
Diffstat (limited to 'pkgs/top-level')
-rw-r--r--pkgs/top-level/all-packages.nix126
-rw-r--r--pkgs/top-level/default.nix19
-rw-r--r--pkgs/top-level/haskell-packages.nix4
-rw-r--r--pkgs/top-level/release-cross.nix14
-rw-r--r--pkgs/top-level/release-lib.nix5
-rw-r--r--pkgs/top-level/splice.nix83
-rw-r--r--pkgs/top-level/stage.nix86
7 files changed, 241 insertions, 96 deletions
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8e7bb79858f..1d924df6aea 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -10,26 +10,12 @@ self: pkgs:
 
 with pkgs;
 
-let
-  defaultScope = pkgs // pkgs.xorg;
-in
-
 {
 
   # Allow callPackage to fill in the pkgs argument
   inherit pkgs;
 
 
-  # We use `callPackage' to be able to omit function arguments that
-  # can be obtained from `pkgs' or `pkgs.xorg' (i.e. `defaultScope').
-  # Use `newScope' for sets of packages in `pkgs' (see e.g. `gnome'
-  # below).
-  callPackage = newScope {};
-
-  callPackages = lib.callPackagesWith defaultScope;
-
-  newScope = extra: lib.callPackageWith (defaultScope // extra);
-
   # Override system. This is useful to build i686 packages on x86_64-linux.
   forceSystem = system: kernel: nixpkgsFun {
     inherit system;
@@ -39,15 +25,9 @@ in
   # Used by wine, firefox with debugging version of Flash, ...
   pkgsi686Linux = forceSystem "i686-linux" "i386";
 
-  callPackage_i686 = lib.callPackageWith (pkgsi686Linux // pkgsi686Linux.xorg);
+  callPackage_i686 = pkgsi686Linux.callPackage;
 
-  forceNativeDrv = drv:
-    # Even when cross compiling, some packages come from the stdenv's
-    # bootstrapping package set. Those packages are only built for the native
-    # platform.
-    if crossSystem != null && drv ? crossDrv
-    then drv // { crossDrv = drv.nativeDrv; }
-    else drv;
+  forcedNativePackages = if hostPlatform == buildPlatform then pkgs else buildPackages;
 
   # A stdenv capable of building 32-bit binaries.  On x86_64-linux,
   # it uses GCC compiled with multilib support; on i686-linux, it's
@@ -3274,7 +3254,7 @@ in
   pngout = callPackage ../tools/graphics/pngout { };
 
   hurdPartedCross =
-    if crossSystem != null && crossSystem.config == "i586-pc-gnu"
+    if targetPlatform != buildPlatform && targetPlatform.config == "i586-pc-gnu"
     then (makeOverridable
             ({ hurd }:
               (parted.override {
@@ -4779,44 +4759,48 @@ in
 
   gccApple = throw "gccApple is no longer supported";
 
-  gccCrossStageStatic = let
+  gccCrossStageStatic = assert targetPlatform != buildPlatform; let
     libcCross1 =
       if stdenv.cross.libc == "msvcrt" then windows.mingw_w64_headers
       else if stdenv.cross.libc == "libSystem" then darwin.xcode
       else null;
     in wrapGCCCross {
-      gcc = forceNativeDrv (gcc.cc.override {
-        cross = crossSystem;
+      gcc = forcedNativePackages.gcc.cc.override {
+        cross = targetPlatform;
         crossStageStatic = true;
         langCC = false;
         libcCross = libcCross1;
         enableShared = false;
-      });
+        # Why is this needed?
+        inherit (forcedNativePackages) binutilsCross;
+      };
       libc = libcCross1;
       binutils = binutilsCross;
-      cross = crossSystem;
+      cross = targetPlatform;
   };
 
   # Only needed for mingw builds
-  gccCrossMingw2 = wrapGCCCross {
+  gccCrossMingw2 = assert targetPlatform != buildPlatform; wrapGCCCross {
     gcc = gccCrossStageStatic.gcc;
     libc = windows.mingw_headers2;
     binutils = binutilsCross;
-    cross = assert crossSystem != null; crossSystem;
+    cross = targetPlatform;
   };
 
-  gccCrossStageFinal = wrapGCCCross {
-    gcc = forceNativeDrv (gcc.cc.override {
-      cross = crossSystem;
+  gccCrossStageFinal = assert targetPlatform != buildPlatform; wrapGCCCross {
+    gcc = forcedNativePackages.gcc.cc.override {
+      cross = targetPlatform;
       crossStageStatic = false;
 
       # XXX: We have troubles cross-compiling libstdc++ on MinGW (see
       # <http://hydra.nixos.org/build/4268232>), so don't even try.
-      langCC = crossSystem.config != "i686-pc-mingw32";
-    });
+      langCC = targetPlatform.config != "i686-pc-mingw32";
+      # Why is this needed?
+      inherit (forcedNativePackages) binutilsCross;
+    };
     libc = libcCross;
     binutils = binutilsCross;
-    cross = crossSystem;
+    cross = targetPlatform;
   };
 
   gcc45 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/4.5 {
@@ -4834,7 +4818,7 @@ in
     # and host != build), `cross' must be null but the cross-libc must still
     # be passed.
     cross = null;
-    libcCross = if crossSystem != null then libcCross else null;
+    libcCross = if targetPlatform != buildPlatform then libcCross else null;
   }));
 
   gcc48 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/4.8 {
@@ -4847,7 +4831,7 @@ in
     # and host != build), `cross' must be null but the cross-libc must still
     # be passed.
     cross = null;
-    libcCross = if crossSystem != null then libcCross else null;
+    libcCross = if targetPlatform != buildPlatform then libcCross else null;
 
     isl = if !stdenv.isDarwin then isl_0_14 else null;
     cloog = if !stdenv.isDarwin then cloog else null;
@@ -4864,7 +4848,7 @@ in
     # and host != build), `cross' must be null but the cross-libc must still
     # be passed.
     cross = null;
-    libcCross = if crossSystem != null then libcCross else null;
+    libcCross = if targetPlatform != buildPlatform then libcCross else null;
 
     isl = if !stdenv.isDarwin then isl_0_11 else null;
 
@@ -4881,7 +4865,7 @@ in
     # and host != build), `cross' must be null but the cross-libc must still
     # be passed.
     cross = null;
-    libcCross = if crossSystem != null then libcCross else null;
+    libcCross = if targetPlatform != buildPlatform then libcCross else null;
 
     isl = if !stdenv.isDarwin then isl_0_14 else null;
   }));
@@ -4896,7 +4880,7 @@ in
     # and host != build), `cross' must be null but the cross-libc must still
     # be passed.
     cross = null;
-    libcCross = if crossSystem != null then libcCross else null;
+    libcCross = if targetPlatform != buildPlatform then libcCross else null;
 
     isl = if !stdenv.isDarwin then isl_0_14 else null;
   }));
@@ -5029,7 +5013,7 @@ in
 
   # Haskell and GHC
 
-  haskell = callPackage ./haskell-packages.nix { inherit crossSystem; };
+  haskell = callPackage ./haskell-packages.nix { };
 
   haskellPackages = haskell.packages.ghc801.override {
     overrides = config.haskellPackageOverrides or (self: super: {});
@@ -5507,12 +5491,12 @@ in
   wrapGCCCross =
     {gcc, libc, binutils, cross, shell ? "", name ? "gcc-cross-wrapper"}:
 
-    forceNativeDrv (callPackage ../build-support/gcc-cross-wrapper {
+    forcedNativePackages.callPackage ../build-support/gcc-cross-wrapper {
       nativeTools = false;
       nativeLibc = false;
       noLibc = (libc == null);
       inherit gcc binutils libc shell name cross;
-    });
+    };
 
   # prolog
   yap = callPackage ../development/compilers/yap { };
@@ -6092,12 +6076,12 @@ in
     gold = false;
   });
 
-  binutilsCross = assert crossSystem != null; lowPrio (forceNativeDrv (
-    if crossSystem.libc == "libSystem" then darwin.cctools_cross
-    else binutils.override {
+  binutilsCross = assert targetPlatform != buildPlatform; lowPrio (
+    if targetPlatform.libc == "libSystem" then darwin.cctools_cross
+    else forcedNativePackages.binutils.override {
       noSysDirs = true;
-      cross = crossSystem;
-    }));
+      cross = targetPlatform;
+    });
 
   bison2 = callPackage ../development/tools/parsing/bison/2.x.nix { };
   bison3 = callPackage ../development/tools/parsing/bison/3.x.nix { };
@@ -6566,9 +6550,9 @@ in
      cross_renaming: we should make all programs use pkgconfig as
      nativeBuildInput after the renaming.
      */
-  pkgconfig = forceNativeDrv (callPackage ../development/tools/misc/pkgconfig {
+  pkgconfig = forcedNativePackages.callPackage ../development/tools/misc/pkgconfig {
     fetchurl = fetchurlBoot;
-  });
+  };
   pkgconfigUpstream = lowPrio (pkgconfig.override { vanilla = true; });
 
   postiats-utilities = callPackage ../development/tools/postiats-utilities {};
@@ -6742,7 +6726,7 @@ in
   gdbGuile = lowPrio (gdb.override { inherit guile; });
 
   gdbCross = lowPrio (callPackage ../development/tools/misc/gdb {
-    target = crossSystem;
+    target = if targetPlatform != buildPlatform then targetPlatform else null;
   });
 
   gdb-multitarget = lowPrio (gdb.override { multitarget = true; });
@@ -7344,10 +7328,10 @@ in
     withGd = true;
   };
 
-  glibcCross = forceNativeDrv (glibc.override {
+  glibcCross = forcedNativePackages.glibc.override {
     gccCross = gccCrossStageStatic;
     linuxHeaders = linuxHeadersCross;
-  });
+  };
 
   # We can choose:
   libcCrossChooser = name: if name == "glibc" then glibcCross
@@ -7356,7 +7340,7 @@ in
     else if name == "libSystem" then darwin.xcode
     else throw "Unknown libc";
 
-  libcCross = assert crossSystem != null; libcCrossChooser crossSystem.libc;
+  libcCross = assert targetPlatform != buildPlatform; libcCrossChooser targetPlatform.libc;
 
   # Only supported on Linux
   glibcLocales = if stdenv.isLinux then callPackage ../development/libraries/glibc/locales.nix { } else null;
@@ -8265,9 +8249,9 @@ in
   # glibc provides libiconv so systems with glibc don't need to build libiconv
   # separately, but we also provide libiconvReal, which will always be a
   # standalone libiconv, just in case you want it
-  libiconv = if crossSystem != null then
-    (if crossSystem.libc == "glibc" then libcCross
-      else if crossSystem.libc == "libSystem" then darwin.libiconv
+  libiconv = if stdenv ? cross then
+    (if stdenv.cross.libc == "glibc" then libcCross
+      else if stdenv.cross.libc == "libSystem" then darwin.libiconv
       else libiconvReal)
     else if stdenv.isGlibc then glibcIconv stdenv.cc.libc
     else if stdenv.isDarwin then darwin.libiconv
@@ -10918,8 +10902,8 @@ in
     cmdline = callPackage ../os-specific/darwin/command-line-tools {};
     apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
   in apple-source-releases // rec {
-    cctools_cross = callPackage (forceNativeDrv (callPackage ../os-specific/darwin/cctools/port.nix {}).cross) {
-      cross = assert crossSystem != null; crossSystem;
+    cctools_cross = callPackage (forcedNativePackages.callPackage ../os-specific/darwin/cctools/port.nix {}).cross {
+      cross = assert targetPlatform != buildPlatform; targetPlatform;
       inherit maloader;
       xctoolchain = xcode.toolchain;
     };
@@ -10992,7 +10976,7 @@ in
   libossp_uuid = callPackage ../development/libraries/libossp-uuid { };
 
   libuuid =
-    if crossSystem != null && crossSystem.config == "i586-pc-gnu"
+    if targetPlatform != buildPlatform && targetPlatform.config == "i586-pc-gnu"
     then (utillinuxMinimal // {
       crossDrv = lib.overrideDerivation utillinuxMinimal.crossDrv (args: {
         # `libblkid' fails to build on GNU/Hurd.
@@ -11077,7 +11061,7 @@ in
 
   # GNU/Hurd core packages.
   gnu = recurseIntoAttrs (callPackage ../os-specific/gnu {
-    inherit platform crossSystem;
+    inherit platform;
   });
 
   hwdata = callPackage ../os-specific/linux/hwdata { };
@@ -11156,13 +11140,13 @@ in
 
   linuxHeaders = linuxHeaders_4_4;
 
-  linuxHeaders24Cross = forceNativeDrv (callPackage ../os-specific/linux/kernel-headers/2.4.nix {
-    cross = assert crossSystem != null; crossSystem;
-  });
+  linuxHeaders24Cross = forcedNativePackages.callPackage ../os-specific/linux/kernel-headers/2.4.nix {
+    cross = assert targetPlatform != buildPlatform; targetPlatform;
+  };
 
-  linuxHeaders26Cross = forceNativeDrv (callPackage ../os-specific/linux/kernel-headers/4.4.nix {
-    cross = assert crossSystem != null; crossSystem;
-  });
+  linuxHeaders26Cross = forcedNativePackages.callPackage ../os-specific/linux/kernel-headers/4.4.nix {
+    cross = assert targetPlatform != buildPlatform; targetPlatform;
+  };
 
   linuxHeaders_3_18 = callPackage ../os-specific/linux/kernel-headers/3.18.nix { };
 
@@ -11173,8 +11157,8 @@ in
     else if ver == "2.6" then linuxHeaders26Cross
     else throw "Unknown linux kernel version";
 
-  linuxHeadersCross = assert crossSystem != null;
-    linuxHeadersCrossChooser crossSystem.platform.kernelMajor;
+  linuxHeadersCross = assert targetPlatform != buildPlatform;
+    linuxHeadersCrossChooser targetPlatform.platform.kernelMajor;
 
   kernelPatches = callPackage ../os-specific/linux/kernel/patches.nix { };
 
@@ -11839,7 +11823,7 @@ in
   uclibcCross = lowPrio (callPackage ../os-specific/linux/uclibc {
     linuxHeaders = linuxHeadersCross;
     gccCross = gccCrossStageStatic;
-    cross = assert crossSystem != null; crossSystem;
+    cross = assert targetPlatform != buildPlatform; targetPlatform;
   });
 
   udev = systemd;
diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix
index a146dad63bc..3c67d316f7c 100644
--- a/pkgs/top-level/default.nix
+++ b/pkgs/top-level/default.nix
@@ -83,7 +83,24 @@ in let
   boot = import ../stdenv/booter.nix { inherit lib allPackages; };
 
   stages = stdenvStages {
-    inherit lib system platform crossSystem config overlays;
+    # One would think that `localSystem` and `crossSystem` overlap horribly with
+    # the three `*Platforms` (`buildPlatform`, `hostPlatform,` and
+    # `targetPlatform`; see `stage.nix` or the manual). Actually, those
+    # identifiers I, @Ericson2314, purposefully not used here to draw a subtle
+    # but important distinction:
+    #
+    # While the granularity of having 3 platforms is necessary to properly
+    # *build* packages, it is overkill for specifying the user's *intent* when
+    # making a build plan or package set. A simple "build vs deploy" dichotomy
+    # is adequate: the "sliding window" principle described in the manual shows
+    # how to interpolate between the these two "end points" to get the 3
+    # platform triple for each bootstrapping stage.
+    #
+    # Also, less philosophically but quite practically, `crossSystem` should be
+    # null when one doesn't want to cross-compile, while the `*Platform`s are
+    # always non-null. `localSystem` is always non-null.
+    localSystem = { inherit system platform; };
+    inherit lib crossSystem config overlays;
   };
 
   pkgs = boot stages;
diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix
index 5b14af145e9..7309121486e 100644
--- a/pkgs/top-level/haskell-packages.nix
+++ b/pkgs/top-level/haskell-packages.nix
@@ -1,4 +1,4 @@
-{ pkgs, callPackage, stdenv, crossSystem }:
+{ pkgs, callPackage, stdenv, buildPlatform, targetPlatform }:
 
 rec {
 
@@ -55,7 +55,7 @@ rec {
     ghcHEAD = callPackage ../development/compilers/ghc/head.nix rec {
       bootPkgs = packages.ghc7103;
       inherit (bootPkgs) alex happy;
-      inherit crossSystem;
+      inherit buildPlatform targetPlatform;
       selfPkgs = packages.ghcHEAD;
     };
     ghcjs = packages.ghc7103.callPackage ../development/compilers/ghcjs {
diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix
index f582bcf3b32..48f183162cf 100644
--- a/pkgs/top-level/release-cross.nix
+++ b/pkgs/top-level/release-cross.nix
@@ -32,8 +32,10 @@ let
 in
 
 {
-  # These `nativeDrv`s should be identical to their vanilla ones --- cross
-  # compiling should not affect the native derivation.
+  # These derivations from a cross package set's `buildPackages` should be
+  # identical to their vanilla equivalents --- none of these package should
+  # observe the target platform which is the only difference between those
+  # package sets.
   ensureUnaffected = let
     # Absurd values are fine here, as we are not building anything. In fact,
     # there probably a good idea to try to be "more parametric" --- i.e. avoid
@@ -47,8 +49,12 @@ in
     # good idea lest there be some irrelevant pass-through debug attrs that
     # cause false negatives.
     testEqualOne = path: system: let
-      f = attrs: builtins.toString (lib.getAttrFromPath path (allPackages attrs));
-    in assert f { inherit system; } == f { inherit system crossSystem; }; true;
+      f = path: attrs: builtins.toString (lib.getAttrFromPath path (allPackages attrs));
+    in assert
+        f path { inherit system; }
+        ==
+        f (["buildPackages"] ++ path) { inherit system crossSystem; };
+      true;
 
     testEqual = path: systems: forAllSupportedSystems systems (testEqualOne path);
 
diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix
index 5fe87711c01..04a57ef8063 100644
--- a/pkgs/top-level/release-lib.nix
+++ b/pkgs/top-level/release-lib.nix
@@ -76,8 +76,9 @@ rec {
    * parameter for allPackages, defining the target platform for cross builds,
    * and triggering the build of the host derivation (cross built - crossDrv). */
   mapTestOnCross = crossSystem: mapAttrsRecursive
-    (path: systems: testOnCross crossSystem systems
-      (pkgs: addMetaAttrs { maintainers = crossMaintainers; } (getAttrFromPath path pkgs)));
+    (path: systems: testOnCross crossSystem systems (pkgs: addMetaAttrs
+      { maintainers = crossMaintainers; }
+      (getAttrFromPath path pkgs.splicedPackages)));
 
 
   /* Recursively map a (nested) set of derivations to an isomorphic
diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix
new file mode 100644
index 00000000000..7afbd956d5b
--- /dev/null
+++ b/pkgs/top-level/splice.nix
@@ -0,0 +1,83 @@
+# The `splicedPackages' package set, and its use by `callPackage`
+#
+# The `buildPackages` pkg set is a new concept, and the vast majority package
+# expression (the other *.nix files) are not designed with it in mind. This
+# presents us with a problem with how to get the right version (build-time vs
+# run-time) of a package to a consumer that isn't used to thinking so cleverly.
+#
+# The solution is to splice the package sets together as we do below, so every
+# `callPackage`d expression in fact gets both versions. Each# derivation (and
+# each derivation's outputs) consists of the run-time version, augmented with a
+# `nativeDrv` field for the build-time version, and `crossDrv` field for the
+# run-time version.
+#
+# We could have used any names we want for the disambiguated versions, but
+# `crossDrv` and `nativeDrv` were somewhat similarly used for the old
+# cross-compiling infrastructure. The names are mostly invisible as
+# `mkDerivation` knows how to pull out the right ones for `buildDepends` and
+# friends, but a few packages use them directly, so it seemed efficient (to
+# @Ericson2314) to reuse those names, at least initially, to minimize breakage.
+#
+# For performance reasons, rather than uniformally splice in all cases, we only
+# do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice`
+# parameter there the boolean value of that equality check.
+lib: pkgs: actuallySplice:
+
+let
+  defaultBuildScope = pkgs.buildPackages // pkgs.buildPackages.xorg;
+  # TODO(@Ericson2314): we shouldn't preclude run-time fetching by removing
+  # these attributes. We should have a more general solution for selecting
+  # whether `nativeDrv` or `crossDrv` is the default in `defaultScope`.
+  pkgsWithoutFetchers = lib.filterAttrs (n: _: !lib.hasPrefix "fetch" n) pkgs;
+  defaultRunScope = pkgsWithoutFetchers // pkgs.xorg;
+
+  splicer = buildPkgs: runPkgs: let
+    mash = buildPkgs // runPkgs;
+    merge = name: {
+      inherit name;
+      value = let
+        defaultValue = mash.${name};
+        buildValue = buildPkgs.${name} or {};
+        runValue = runPkgs.${name} or {};
+        augmentedValue = defaultValue
+          // (lib.optionalAttrs (buildPkgs ? ${name}) { nativeDrv = buildValue; })
+          // (lib.optionalAttrs (runPkgs ? ${name}) { crossDrv = runValue; });
+        # Get the set of outputs of a derivation
+        getOutputs = value:
+          lib.genAttrs (value.outputs or []) (output: value.${output});
+      in
+        # Certain *Cross derivations will fail assertions, but we need their
+        # nativeDrv. We are assuming anything that fails to evaluate is an
+        # attrset (including derivation) and thus can be unioned.
+        if !(builtins.tryEval defaultValue).success then augmentedValue
+        # The derivation along with its outputs, which we recur
+        # on to splice them together.
+        else if lib.isDerivation defaultValue then augmentedValue
+          // splicer (getOutputs buildValue) (getOutputs runValue)
+        # Just recur on plain attrsets
+        else if lib.isAttrs defaultValue then splicer buildValue runValue
+        # Don't be fancy about non-derivations. But we could have used used
+        # `__functor__` for functions instead.
+        else defaultValue;
+    };
+  in lib.listToAttrs (map merge (lib.attrNames mash));
+
+  splicedPackages =
+    if actuallySplice
+    then splicer defaultBuildScope defaultRunScope
+    else pkgs // pkgs.xorg;
+
+in
+
+{
+  splicedPackages = splicedPackages // { recurseForDerivations = false; };
+
+  # We use `callPackage' to be able to omit function arguments that can be
+  # obtained `pkgs` or `buildPackages` and their `xorg` package sets. Use
+  # `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
+  callPackage = pkgs.newScope {};
+
+  callPackages = lib.callPackagesWith splicedPackages;
+
+  newScope = extra: lib.callPackageWith (splicedPackages // extra);
+}
diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index cbf65870eb7..6febedb79f3 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -9,8 +9,45 @@
    import `pkgs/default.nix` or `default.nix`. */
 
 
-{ # The system (e.g., `i686-linux') for which to build the packages.
-  system
+{ ## Misc parameters kept the same for all stages
+  ##
+
+  # Utility functions, could just import but passing in for efficiency
+  lib
+
+, # Use to reevaluate Nixpkgs; a dirty hack that should be removed
+  nixpkgsFun
+
+  ## Platform parameters
+  ##
+  ## The "build" "host" "target" terminology below comes from GNU Autotools. See
+  ## its documentation for more information on what those words mean. Note that
+  ## each should always be defined, even when not cross compiling.
+  ##
+  ## For purposes of bootstrapping, think of each stage as a "sliding window"
+  ## over a list of platforms. Specifically, the host platform of the previous
+  ## stage becomes the build platform of the current one, and likewise the
+  ## target platform of the previous stage becomes the host platform of the
+  ## current one.
+  ##
+
+, # The platform on which packages are built. Consists of `system`, a
+  # string (e.g.,`i686-linux') identifying the most import attributes of the
+  # build platform, and `platform` a set of other details.
+  buildPlatform
+
+, # The platform on which packages run.
+  hostPlatform
+
+, # The platform which build tools (especially compilers) build for in this stage,
+  targetPlatform
+
+  ## Other parameters
+  ##
+
+, # The package set used at build-time. If null, `buildPackages` will
+  # be defined internally as the produced package set as itself.
+  buildPackages
 
 , # The standard environment to use for building packages.
   stdenv
@@ -21,21 +58,19 @@
   allowCustomOverrides
 
 , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
-  # outside of the store.  Thus, GCC, GFortran, & co. must always look for
-  # files in standard system directories (/usr/include, etc.)
-  noSysDirs ? (system != "x86_64-freebsd" && system != "i686-freebsd"
-               && system != "x86_64-solaris"
-               && system != "x86_64-kfreebsd-gnu")
+  # outside of the store.  Thus, GCC, GFortran, & co. must always look for files
+  # in standard system directories (/usr/include, etc.)
+  noSysDirs ? buildPlatform.system != "x86_64-freebsd"
+           && buildPlatform.system != "i686-freebsd"
+           && buildPlatform.system != "x86_64-solaris"
+           && buildPlatform.system != "x86_64-kfreebsd-gnu"
 
 , # The configuration attribute set
   config
 
-, overlays # List of overlays to use in the fix-point.
-
-, crossSystem
-, platform
-, lib
-, nixpkgsFun
+, # A list of overlays (Additional `self: super: { .. }` customization
+  # functions) to be fixed together in the produced package set
+  overlays
 }:
 
 let
@@ -50,11 +85,28 @@ let
     };
 
   stdenvBootstappingAndPlatforms = self: super: {
-    stdenv = stdenv // { inherit platform; };
-    inherit
-      system platform crossSystem;
+    buildPackages = (if buildPackages == null then self else buildPackages)
+      // { recurseForDerivations = false; };
+    inherit stdenv
+      buildPlatform hostPlatform targetPlatform;
   };
 
+  # The old identifiers for cross-compiling. These should eventually be removed,
+  # and the packages that rely on them refactored accordingly.
+  platformCompat = self: super: let
+    # TODO(@Ericson2314) this causes infinite recursion
+    #inherit (self) buildPlatform hostPlatform targetPlatform;
+  in {
+    stdenv = super.stdenv // {
+      inherit (buildPlatform) platform;
+    } // lib.optionalAttrs (targetPlatform != buildPlatform) {
+      cross = targetPlatform;
+    };
+    inherit (buildPlatform) system platform;
+  };
+
+  splice = self: super: import ./splice.nix lib self (buildPackages != null);
+
   allPackages = self: super:
     let res = import ./all-packages.nix
       { inherit lib nixpkgsFun noSysDirs config; }
@@ -83,8 +135,10 @@ let
   # The complete chain of package set builders, applied from top to bottom
   toFix = lib.foldl' (lib.flip lib.extends) (self: {}) ([
     stdenvBootstappingAndPlatforms
+    platformCompat
     stdenvAdapters
     trivialBuilders
+    splice
     allPackages
     aliases
     stdenvOverrides