summary refs log tree commit diff
path: root/pkgs/stdenv/linux
diff options
context:
space:
mode:
authorGergely Risko <errge@nilcons.com>2014-09-11 01:18:14 +0200
committerGergely Risko <errge@nilcons.com>2014-09-14 21:35:54 +0200
commitfca5d864b6e76f6985aa8a991df64ed94a377333 (patch)
tree1a0b3fe9c1f0fb24d0bead85ef237afad0380b80 /pkgs/stdenv/linux
parentefcb00d002d3bcb830e2aad949044f5f1a1117c6 (diff)
downloadnixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar.gz
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar.bz2
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar.lz
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar.xz
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.tar.zst
nixlib-fca5d864b6e76f6985aa8a991df64ed94a377333.zip
pkgs/stdenv/linux: stageFun refactoring
The stage3.extraAttrs.glibc argument was required for this whole build
procedure to correctly work and it was very-very hard to see why (the
comment said something about gcc47, but we're using gcc48 now).

This stage3.extraAttrs.glibc goes into stage3.stdenv.glibc after some
arg passing, and in pkgs/development/compiler/gcc an (stdenv ? glibc)
boolean expression decides to override /usr/include during the GCC
build.

All of our stages are built with glibc, so this refactoring moves this
repeating specification of glibc (once for gcc wrapper and once here for
extraAttrs) to stageFun, by getting rid of wrapGCC, as we were using
that in all of the stages anyways.

Incidentally it turned out, that this stdenv.glibc inconsistency caused
some random other stuff to behave differently:
  - stage1.pkgs.perl has threading disabled,
  - stage4.pkgs.coreutils (the production coreutils) has testing disabled.

Leave this historical accidents as they are in this commit, so the scope
of this commit can stay as a refactoring only, these issues will be
fixed in separate commits.

This commit doesn't change the derivation or the output hash of
stdenvLinux.
Diffstat (limited to 'pkgs/stdenv/linux')
-rw-r--r--pkgs/stdenv/linux/default.nix118
1 files changed, 67 insertions, 51 deletions
diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index feb8a5172459..b5e92fb8e1cf 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -63,23 +63,11 @@ rec {
   };
 
 
-  # A helper function to call gcc-wrapper.
-  wrapGCC =
-    { gcc, libc, binutils, coreutils, name }:
-
-    lib.makeOverridable (import ../../build-support/gcc-wrapper) {
-      nativeTools = false;
-      nativeLibc = false;
-      inherit gcc binutils coreutils libc name;
-      stdenv = stage0.stdenv;
-    };
-
-
   # This function builds the various standard environments used during
   # the bootstrap.  In all stages, we build an stdenv and the package
   # set that can be built with that stdenv.
   stageFun =
-    {gcc, extraAttrs ? {}, overrides ? (pkgs: {}), extraBuildInputs ? []}:
+    {gccPlain, glibc, binutils, coreutils, name, overrides ? (pkgs: {}), extraBuildInputs ? []}:
 
     let
 
@@ -99,10 +87,28 @@ rec {
           stdenv = stage0.stdenv;
           curl = bootstrapTools;
         };
-        inherit gcc;
-        # Having the proper 'platform' in all the stdenvs allows getting proper
-        # linuxHeaders for example.
-        extraAttrs = extraAttrs // { inherit platform; };
+
+        gcc = if isNull gccPlain
+              then "/no-such-path"
+              else lib.makeOverridable (import ../../build-support/gcc-wrapper) {
+          nativeTools = false;
+          nativeLibc = false;
+          gcc = gccPlain;
+          libc = glibc;
+          inherit binutils coreutils;
+          name = name;
+          stdenv = stage0.stdenv;
+        };
+
+        extraAttrs = {
+          # Having the proper 'platform' in all the stdenvs allows getting proper
+          # linuxHeaders for example.
+          inherit platform;
+
+          # stdenv.glibc is used by GCC build to figure out the system-level
+          # /usr/include directory.
+          inherit glibc;
+        };
         overrides = pkgs: (overrides pkgs) // { fetchurl = thisStdenv.fetchurlBoot; };
       };
 
@@ -117,7 +123,11 @@ rec {
   # Build a dummy stdenv with no GCC or working fetchurl.  This is
   # because we need a stdenv to build the GCC wrapper and fetchurl.
   stage0 = stageFun {
-    gcc = "/no-such-path";
+    gccPlain = null;
+    glibc = null;
+    binutils = null;
+    coreutils = null;
+    name = null;
 
     overrides = pkgs: {
       # The Glibc include directory cannot have the same prefix as the
@@ -148,17 +158,19 @@ rec {
   # simply re-export those packages in the middle stage(s) using the
   # overrides attribute and the inherit syntax.
   stage1 = stageFun {
-    gcc = wrapGCC {
-      gcc = bootstrapTools;
-      libc = stage0.pkgs.glibc;
-      binutils = bootstrapTools;
-      coreutils = bootstrapTools;
-      name = "bootstrap-gcc-wrapper";
-    };
+    gccPlain = bootstrapTools;
+    inherit (stage0.pkgs) glibc;
+    binutils = bootstrapTools;
+    coreutils = bootstrapTools;
+    name = "bootstrap-gcc-wrapper";
+
     # Rebuild binutils to use from stage2 onwards.
     overrides = pkgs: {
       binutils = pkgs.binutils.override { gold = false; };
       inherit (stage0.pkgs) glibc;
+
+      # TODO(errge) This was accidentally like this historically, most probably not needed
+      perl = pkgs.perl.override { stdenv = stage1.stdenv.override { extraAttrs = { inherit platform; }; }; };
     };
   };
 
@@ -166,13 +178,12 @@ rec {
   # 2nd stdenv that contains our own rebuilt binutils and is used for
   # compiling our own Glibc.
   stage2 = stageFun {
-    gcc = wrapGCC {
-      gcc = bootstrapTools;
-      libc = stage1.pkgs.glibc;
-      binutils = stage1.pkgs.binutils;
-      coreutils = bootstrapTools;
-      name = "bootstrap-gcc-wrapper";
-    };
+    gccPlain = bootstrapTools;
+    inherit (stage1.pkgs) glibc;
+    binutils = stage1.pkgs.binutils;
+    coreutils = bootstrapTools;
+    name = "bootstrap-gcc-wrapper";
+
     overrides = pkgs: {
       inherit (stage1.pkgs) perl binutils paxctl;
       # This also contains the full, dynamically linked, final Glibc.
@@ -184,13 +195,11 @@ rec {
   # one uses the rebuilt Glibc from stage2.  It still uses the recent
   # binutils and rest of the bootstrap tools, including GCC.
   stage3 = stageFun {
-    gcc = wrapGCC {
-      gcc = bootstrapTools;
-      libc = stage2.pkgs.glibc;
-      binutils = stage2.pkgs.binutils;
-      coreutils = bootstrapTools;
-      name = "bootstrap-gcc-wrapper";
-    };
+    gccPlain = bootstrapTools;
+    inherit (stage2.pkgs) glibc binutils;
+    coreutils = bootstrapTools;
+    name = "bootstrap-gcc-wrapper";
+
     overrides = pkgs: {
       inherit (stage2.pkgs) binutils glibc perl patchelf linuxHeaders;
       # Link GCC statically against GMP etc.  This makes sense because
@@ -202,9 +211,7 @@ rec {
       isl = pkgs.isl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
       cloog = pkgs.cloog.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
       ppl = pkgs.ppl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
-    };
-    extraAttrs = {
-      glibc = stage2.pkgs.glibc;  # Required by gcc47 build
+      gccPlain = pkgs.gcc.gcc;
     };
     extraBuildInputs = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
   };
@@ -213,13 +220,10 @@ rec {
   # Construct a fourth stdenv that uses the new GCC.  But coreutils is
   # still from the bootstrap tools.
   stage4 = stageFun {
-    gcc = wrapGCC {
-      gcc = stage3.pkgs.gcc.gcc;
-      libc = stage3.pkgs.glibc;
-      binutils = stage3.pkgs.binutils;
-      coreutils = bootstrapTools;
-      name = "";
-    };
+    inherit (stage3.pkgs) gccPlain glibc binutils;
+    coreutils = bootstrapTools;
+    name = "";
+
     overrides = pkgs: {
       # Zlib has to be inherited and not rebuilt in this stage,
       # because gcc (since JAR support) already depends on zlib, and
@@ -227,12 +231,24 @@ rec {
       # other purposes (binutils and top-level pkgs) too.
       inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib linuxHeaders;
 
-      gcc = (wrapGCC {
+      # Accidental historical garbage
+      #
+      # TODO(errge): this historical mistake accidentally disables
+      # tests for the production coreutils, we definitely don't want
+      # that, so fix this in another commit!  (But will change drv and
+      # out hashes.)
+      coreutils = pkgs.coreutils.override { stdenv = stage4.stdenv.override { extraAttrs = { inherit platform; }; }; };
+
+      gcc = import ../../build-support/gcc-wrapper {
+        nativeTools = false;
+        nativeLibc = false;
         gcc = stage4.stdenv.gcc.gcc;
         libc = stage4.pkgs.glibc;
         inherit (stage4.pkgs) binutils coreutils;
         name = "";
-      }).override { shell = stage4.pkgs.bash + "/bin/bash"; };
+        stdenv = stage0.stdenv; # TODO(errge): legacy
+        shell = stage4.pkgs.bash + "/bin/bash";
+      };
     };
     extraBuildInputs = [ stage3.pkgs.patchelf stage3.pkgs.xz ];
   };