about summary refs log tree commit diff
path: root/pkgs/stdenv/linux
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2014-08-30 08:33:10 +0200
committerVladimír Čunát <vcunat@gmail.com>2014-08-30 08:33:10 +0200
commit031baae714f2219f33fa713e4ed5a8926e620f79 (patch)
treee02f50390d7f2b469070bf313d017fe3221796b6 /pkgs/stdenv/linux
parenta70180ba73553e66d4f5555d2b4d232b4990718b (diff)
parent60902b97fe4a96d370bc0c5e3690fa45da77d78d (diff)
downloadnixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar.gz
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar.bz2
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar.lz
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar.xz
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.tar.zst
nixlib-031baae714f2219f33fa713e4ed5a8926e620f79.zip
Merge branch 'staging' into v/modular
Conflicts (as in p/modular-stdenv):
	pkgs/stdenv/linux/default.nix
Diffstat (limited to 'pkgs/stdenv/linux')
-rw-r--r--pkgs/stdenv/linux/default.nix287
1 files changed, 132 insertions, 155 deletions
diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index a2a971589470..6b15808285b0 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -32,8 +32,8 @@ rec {
   # The bootstrap process proceeds in several steps.
 
 
-  # 1) Create a standard environment by downloading pre-built binaries
-  # of coreutils, GCC, etc.
+  # Create a standard environment by downloading pre-built binaries of
+  # coreutils, GCC, etc.
 
 
   # Download and unpack the bootstrap tools (coreutils, GCC, Glibc, ...).
@@ -63,137 +63,136 @@ rec {
   };
 
 
-  # This function builds the various standard environments used during
-  # the bootstrap.
-  stdenvBootFun =
-    { gcc, extraAttrs ? {}, overrides ? (pkgs: {}), extraBuildInputs ? [], fetchurl }:
-
-    import ../generic {
-      inherit system config extraBuildInputs;
-      name = "stdenv-linux-boot";
-      preHook =
-        ''
-          # Don't patch #!/interpreter because it leads to retained
-          # dependencies on the bootstrapTools in the final stdenv.
-          dontPatchShebangs=1
-          ${commonPreHook}
-        '';
-      shell = "${bootstrapTools}/bin/sh";
-      initialPath = [ bootstrapTools ];
-      fetchurlBoot = fetchurl;
-      inherit gcc;
-      # Having the proper 'platform' in all the stdenvs allows getting proper
-      # linuxHeaders for example.
-      extraAttrs = extraAttrs // { inherit platform; };
-      overrides = pkgs: (overrides pkgs) // {
-        inherit fetchurl;
-      };
-    };
+  # A helper function to call gcc-wrapper.
+  wrapGCC =
+    { gcc, libc, binutils, coreutils, name }:
 
-  # Build a dummy stdenv with no GCC or working fetchurl.  This is
-  # because we need a stdenv to build the GCC wrapper and fetchurl.
-  stdenvLinuxBoot0 = stdenvBootFun {
-    gcc = "/no-such-path";
-    fetchurl = null;
-  };
+    lib.makeOverridable (import ../../build-support/gcc-wrapper) {
+      nativeTools = false;
+      nativeLibc = false;
+      inherit gcc binutils coreutils libc name;
+      stdenv = stage0.stdenv;
+    };
 
 
-  fetchurl = import ../../build-support/fetchurl {
-    stdenv = stdenvLinuxBoot0;
-    curl = bootstrapTools;
-  };
+  # 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: {}), extraPath ? []}:
+
+    let
+
+      thisStdenv = import ../generic {
+        inherit system config;
+        name = "stdenv-linux-boot";
+        preHook =
+          ''
+            # Don't patch #!/interpreter because it leads to retained
+            # dependencies on the bootstrapTools in the final stdenv.
+            dontPatchShebangs=1
+            ${commonPreHook}
+          '';
+        shell = "${bootstrapTools}/bin/sh";
+        initialPath = [bootstrapTools] ++ extraPath;
+        fetchurlBoot = import ../../build-support/fetchurl {
+          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; };
+        overrides = pkgs: (overrides pkgs) // { fetchurl = thisStdenv.fetchurlBoot; };
+      };
 
+      thisPkgs = allPackages {
+        inherit system platform;
+        bootStdenv = thisStdenv;
+      };
 
-  # The Glibc include directory cannot have the same prefix as the GCC
-  # include directory, since GCC gets confused otherwise (it will
-  # search the Glibc headers before the GCC headers).  So create a
-  # dummy Glibc.
-  bootstrapGlibc = stdenvLinuxBoot0.mkDerivation {
-    name = "bootstrap-glibc";
-    buildCommand = ''
-      mkdir -p $out
-      ln -s ${bootstrapTools}/lib $out/lib
-      ln -s ${bootstrapTools}/include-glibc $out/include
-    '';
-  };
+    in { stdenv = thisStdenv; pkgs = thisPkgs; };
 
 
-  # A helper function to call gcc-wrapper.
-  wrapGCC =
-    { gcc ? bootstrapTools, libc, binutils, coreutils, shell ? "", name ? "bootstrap-gcc-wrapper" }:
+  # 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";
 
-    lib.makeOverridable (import ../../build-support/gcc-wrapper) {
-      nativeTools = false;
-      nativeLibc = false;
-      inherit gcc binutils coreutils libc shell name;
-      stdenv = stdenvLinuxBoot0;
+    overrides = pkgs: {
+      # The Glibc include directory cannot have the same prefix as the
+      # GCC include directory, since GCC gets confused otherwise (it
+      # will search the Glibc headers before the GCC headers).  So
+      # create a dummy Glibc here, which will be used in the stdenv of
+      # stage1.
+      glibc = stage0.stdenv.mkDerivation {
+        name = "bootstrap-glibc";
+        buildCommand = ''
+          mkdir -p $out
+          ln -s ${bootstrapTools}/lib $out/lib
+          ln -s ${bootstrapTools}/include-glibc $out/include
+        '';
+      };
     };
+  };
 
 
   # Create the first "real" standard environment.  This one consists
   # of bootstrap tools only, and a minimal Glibc to keep the GCC
   # configure script happy.
-  stdenvLinuxBoot1 = stdenvBootFun {
+  #
+  # For clarity, we only use the previous stage when specifying these
+  # stages.  So stageN should only ever have references for stage{N-1}.
+  #
+  # If we ever need to use a package from more than one stage back, we
+  # simply re-export those packages in the middle stage(s) using the
+  # overrides attribute and the inherit syntax.
+  stage1 = stageFun {
     gcc = wrapGCC {
-      libc = bootstrapGlibc;
+      gcc = bootstrapTools;
+      libc = 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;
     };
-    inherit fetchurl;
-  };
-
-
-  # 2) These are the packages that we can build with the first
-  #    stdenv.  We only need binutils, because recent Glibcs
-  #    require recent Binutils, and those in bootstrap-tools may
-  #    be too old.
-  stdenvLinuxBoot1Pkgs = allPackages {
-    inherit system platform;
-    bootStdenv = stdenvLinuxBoot1;
   };
 
-  binutils1 = stdenvLinuxBoot1Pkgs.binutils.override { gold = false; };
-
 
-  # 3) 2nd stdenv that we will use to build only Glibc.
-  stdenvLinuxBoot2 = stdenvBootFun {
+  # 2nd stdenv that contains our own rebuilt binutils and is used for
+  # compiling our own Glibc.
+  stage2 = stageFun {
     gcc = wrapGCC {
-      libc = bootstrapGlibc;
-      binutils = binutils1;
+      gcc = bootstrapTools;
+      libc = stage1.pkgs.glibc;
+      binutils = stage1.pkgs.binutils;
       coreutils = bootstrapTools;
+      name = "bootstrap-gcc-wrapper";
     };
     overrides = pkgs: {
-      inherit (stdenvLinuxBoot1Pkgs) perl;
+      inherit (stage1.pkgs) perl binutils paxctl;
+      # This also contains the full, dynamically linked, final Glibc.
     };
-    inherit fetchurl;
-  };
-
-
-  # 4) These are the packages that we can build with the 2nd
-  #    stdenv.
-  stdenvLinuxBoot2Pkgs = allPackages {
-    inherit system platform;
-    bootStdenv = stdenvLinuxBoot2;
   };
 
 
-  # 5) Build Glibc with the bootstrap tools.  The result is the full,
-  #    dynamically linked, final Glibc.
-  stdenvLinuxGlibc = stdenvLinuxBoot2Pkgs.glibc;
-
-
-  # 6) Construct a third stdenv identical to the 2nd, except that this
-  #    one uses the Glibc built in step 3.  It still uses the recent
-  #    binutils and the rest of the bootstrap tools, including GCC.
-  stdenvLinuxBoot3 = stdenvBootFun {
+  # Construct a third stdenv identical to the 2nd, except that this
+  # 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 {
-      binutils = binutils1;
+      gcc = bootstrapTools;
+      libc = stage2.pkgs.glibc;
+      binutils = stage2.pkgs.binutils;
       coreutils = bootstrapTools;
-      libc = stdenvLinuxGlibc;
+      name = "bootstrap-gcc-wrapper";
     };
     overrides = pkgs: {
-      glibc = stdenvLinuxGlibc;
-      inherit (stdenvLinuxBoot1Pkgs) perl;
+      inherit (stage2.pkgs) binutils glibc perl;
       # Link GCC statically against GMP etc.  This makes sense because
       # these builds of the libraries are only used by GCC, so it
       # reduces the size of the stdenv closure.
@@ -205,54 +204,36 @@ rec {
       ppl = pkgs.ppl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; };
     };
     extraAttrs = {
-      glibc = stdenvLinuxGlibc; # Required by gcc47 build
+      glibc = stage2.pkgs.glibc;  # Required by gcc47 build
     };
-    extraBuildInputs = [ stdenvLinuxBoot2Pkgs.patchelf stdenvLinuxBoot1Pkgs.paxctl ];
-    inherit fetchurl;
-  };
-
-
-  # 7) The packages that can be built using the third stdenv.
-  stdenvLinuxBoot3Pkgs = allPackages {
-    inherit system platform;
-    bootStdenv = stdenvLinuxBoot3;
+    extraPath = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
   };
 
 
-  # 8) Construct a fourth stdenv identical to the second, except that
-  #    this one uses the new GCC from step 7.  The other tools
-  #    (e.g. coreutils) are still from the bootstrap tools.
-  stdenvLinuxBoot4 = stdenvBootFun {
-    gcc = wrapGCC rec {
-      binutils = binutils1;
+  # 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;
-      libc = stdenvLinuxGlibc;
-      gcc = stdenvLinuxBoot3Pkgs.gcc.gcc;
       name = "";
     };
-    extraBuildInputs = [ stdenvLinuxBoot2Pkgs.patchelf stdenvLinuxBoot3Pkgs.xz.bin ];
+    extraPath = [ stage2.pkgs.patchelf stage3.pkgs.xz ];
     overrides = pkgs: {
-      inherit (stdenvLinuxBoot1Pkgs) perl;
-      inherit (stdenvLinuxBoot3Pkgs) gettext gnum4 gmp;
+      inherit (stage3.pkgs) gettext gnum4 gmp perl glibc;
     };
-    inherit fetchurl;
-  };
-
-
-  # 9) The packages that can be built using the fourth stdenv.
-  stdenvLinuxBoot4Pkgs = allPackages {
-    inherit system platform;
-    bootStdenv = stdenvLinuxBoot4;
   };
 
 
-  # 10) Construct the final stdenv.  It uses the Glibc and GCC, and
-  #     adds in a new binutils that doesn't depend on bootstrap-tools,
-  #     as well as dynamically linked versions of all other tools.
+  # Construct the final stdenv.  It uses the Glibc and GCC, and adds
+  # in a new binutils that doesn't depend on bootstrap-tools, as well
+  # as dynamically linked versions of all other tools.
   #
-  #     When updating stdenvLinux, make sure that the result has no
-  #     dependency (`nix-store -qR') on bootstrapTools or the
-  #     first binutils built.
+  # When updating stdenvLinux, make sure that the result has no
+  # dependency (`nix-store -qR') on bootstrapTools or the first
+  # binutils built.
   stdenvLinux = import ../generic rec {
     inherit system config;
 
@@ -265,37 +246,33 @@ rec {
       '';
 
     initialPath =
-      ((import ../common-path.nix) {pkgs = stdenvLinuxBoot4Pkgs;});
+      ((import ../common-path.nix) {pkgs = stage4.pkgs;});
 
-    extraBuildInputs =
-      [ stdenvLinuxBoot4Pkgs.patchelf stdenvLinuxBoot4Pkgs.paxctl ];
+    extraBuildInputs = [ stage4.pkgs.patchelf stage4.pkgs.paxctl ];
 
-    gcc = wrapGCC rec {
-      inherit (stdenvLinuxBoot4Pkgs) binutils coreutils;
-      libc = stdenvLinuxGlibc;
-      gcc = stdenvLinuxBoot4.gcc.gcc;
-      shell = stdenvLinuxBoot4Pkgs.bash + "/bin/bash";
-      name = "";
-    };
+    shell = stage4.pkgs.bash + "/bin/bash";
 
-    shell = stdenvLinuxBoot4Pkgs.bash + "/bin/bash";
+    gcc = (wrapGCC rec {
+      gcc = stage4.stdenv.gcc.gcc;
+      libc = stage4.pkgs.glibc;
+      inherit (stage4.pkgs) binutils coreutils;
+      name = "";
+    }).override { inherit shell; };
 
-    fetchurlBoot = fetchurl;
+    inherit (stage4.stdenv) fetchurlBoot;
 
     extraAttrs = {
-      glibc = stdenvLinuxGlibc;
+      inherit (stage4.pkgs) glibc;
       inherit platform bootstrapTools;
-      shellPackage = stdenvLinuxBoot4Pkgs.bash;
+      shellPackage = stage4.pkgs.bash;
     };
 
     overrides = pkgs: {
       inherit gcc;
-      inherit (stdenvLinuxBoot3Pkgs) glibc;
-      inherit (stdenvLinuxBoot4Pkgs) binutils;
-      inherit (stdenvLinuxBoot4Pkgs)
-        gzip bzip2 xz bash coreutils diffutils findutils gawk
-        gnumake gnused gnutar gnugrep gnupatch patchelf
-        attr acl pcre paxctl;
+      inherit (stage4.pkgs)
+        gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
+        glibc gnumake gnused gnutar gnugrep gnupatch patchelf
+        attr acl paxctl;
     };
   };