summary refs log tree commit diff
path: root/pkgs/top-level/stage.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/top-level/stage.nix')
-rw-r--r--pkgs/top-level/stage.nix82
1 files changed, 64 insertions, 18 deletions
diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index c100e21473cd..780be566436c 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -9,10 +9,43 @@
    import `pkgs/default.nix` or `default.nix`. */
 
 
-{ # The system (e.g., `i686-linux') for which to build the packages.
-  system
-
-, # the package set used at build-time
+{ ## 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
   buildPackages
 
 , # The standard environment to use for building packages.
@@ -24,21 +57,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
@@ -53,10 +84,24 @@ let
     };
 
   stdenvBootstappingAndPlatforms = self: super: {
-    stdenv = stdenv // { inherit platform; };
     buildPackages = buildPackages // { recurseForDerivations = false; };
-    inherit
-      system platform crossSystem;
+    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;
+    crossSystem = if targetPlatform != buildPlatform then targetPlatform else null;
   };
 
   splice = self: super: import ./splice.nix lib self;
@@ -89,6 +134,7 @@ 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