about summary refs log tree commit diff
path: root/pkgs/stdenv
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/stdenv')
-rw-r--r--pkgs/stdenv/adapters.nix72
-rw-r--r--pkgs/stdenv/default.nix1
-rw-r--r--pkgs/stdenv/generic/default.nix29
-rw-r--r--pkgs/stdenv/generic/setup.sh80
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/bzip2bin0 -> 124936 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/cpiobin0 -> 20280 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/curl.bz2bin0 -> 151568 bytes
-rw-r--r--pkgs/stdenv/linux/bootstrap/armv5tel/default.nix13
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/lnbin0 -> 13728 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/mkdirbin0 -> 15484 bytes
-rwxr-xr-xpkgs/stdenv/linux/bootstrap/armv5tel/shbin0 -> 82672 bytes
-rw-r--r--pkgs/stdenv/linux/default.nix33
-rw-r--r--pkgs/stdenv/linux/make-bootstrap-tools.nix21
-rw-r--r--pkgs/stdenv/linux/scripts/unpack-bootstrap-tools-arm.sh54
-rw-r--r--pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh27
-rw-r--r--pkgs/stdenv/nix/default.nix1
16 files changed, 288 insertions, 43 deletions
diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix
index 9e02a8bd307f..ac9e807801c6 100644
--- a/pkgs/stdenv/adapters.nix
+++ b/pkgs/stdenv/adapters.nix
@@ -107,7 +107,77 @@ rec {
       isStatic = true;
     } // {inherit fetchurl;};
 
+    
+  # Return a modified stdenv that disables building shared libraries.
+  # However, executables will still be dynamically linked.
+  disableSharedLibraries = stdenv: stdenv //
+    { mkDerivation = args: stdenv.mkDerivation (args // {
+        dontDisableStatic = true;
+        configureFlags =
+          (if args ? configureFlags then args.configureFlags else "")
+          + " --disable-shared"; # brrr...
+      });
+    } // {inherit fetchurl;};
+
+    
+  # Return a modified stdenv that adds a cross compiler to the
+  # builds.
+  makeStdenvCross = stdenv: cross: binutilsCross: gccCross: stdenv //
+    { mkDerivation = {name ? "", buildInputs ? [], buildNativeInputs ? [],
+            propagatedBuildInputs ? [], propagatedBuildNativeInputs ? [],
+            selfBuildNativeInput ? false, ...}@args: let
+
+            # *BuildInputs exists temporarily as another name for
+            # *HostInputs.
+
+            getBuildDrv = drv : if (drv ? buildDrv) then drv.buildDrv else drv;
+            buildNativeInputsDrvs = map (getBuildDrv) buildNativeInputs;
+            buildInputsDrvs = map (drv: drv.hostDrv) buildInputs;
+            buildInputsDrvsAsBuildInputs = map (getBuildDrv) buildInputs;
+            propagatedBuildInputsDrvs = map (drv: drv.hostDrv) (propagatedBuildInputs);
+            propagatedBuildNativeInputsDrvs = map (drv: drv.buildDrv)
+                (propagatedBuildNativeInputs);
+
+            # The base stdenv already knows that buildNativeInputs and
+            # buildInputs should be built with the usual gcc-wrapper
+            # And the same for propagatedBuildInputs.
+            buildDrv = stdenv.mkDerivation args;
+
+            # Temporary expression until the cross_renaming, to handle the
+            # case of pkgconfig given as buildInput, but to be used as
+            # buildNativeInput.
+            hostAsBuildDrv = drv: builtins.unsafeDiscardStringContext
+                drv.buildDrv.drvPath == builtins.unsafeDiscardStringContext
+                drv.hostDrv.drvPath;
+            nativeInputsFromBuildInputs = stdenv.lib.filter (hostAsBuildDrv) buildInputs;
+
+            # We should overwrite the input attributes in hostDrv, to overwrite
+            # the defaults for only-native builds in the base stdenv
+            hostDrv = if (cross == null) then buildDrv else
+                stdenv.mkDerivation (args // {
+                    name = name + "-" + cross.config;
+                    buildNativeInputs = buildNativeInputsDrvs
+                      ++ nativeInputsFromBuildInputs
+                      ++ [ gccCross binutilsCross ] ++
+                      stdenv.lib.optional selfBuildNativeInput buildDrv;
+
+                    # Cross-linking dynamic libraries, every buildInput should
+                    # be propagated because ld needs the -rpath-link to find
+                    # any library needed to link the program dynamically at
+                    # loader time. ld(1) explains it.
+                    buildInputs = [];
+                    propagatedBuildInputs = propagatedBuildInputsDrvs ++
+                      buildInputsDrvs;
+                    propagatedBuildNativeInputs = propagatedBuildNativeInputsDrvs;
+
+                    crossConfig = cross.config;
+                });
+        in buildDrv // {
+            inherit hostDrv buildDrv;
+        };
+    } // { inherit cross; };
 
+    
   /* Modify a stdenv so that the specified attributes are added to
      every derivation returned by its mkDerivation function.
 
@@ -211,7 +281,6 @@ rec {
 
   /* Use the trace output to report all processed derivations with their
      license name.
- 
   */
   traceDrvLicenses = stdenv: stdenv //
     { mkDerivation = args:
@@ -233,6 +302,7 @@ rec {
         };
     };
 
+    
   /* Abort if the license predicate is not verified for a derivation
      declared with mkDerivation.
 
diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix
index 37fd75328114..40acb8cfece4 100644
--- a/pkgs/stdenv/default.nix
+++ b/pkgs/stdenv/default.nix
@@ -54,6 +54,7 @@ rec {
   stdenv =
     if stdenvType == "i686-linux" then stdenvLinux else
     if stdenvType == "x86_64-linux" then stdenvLinux else
+    if stdenvType == "armv5tel-linux" then stdenvLinux else
     if stdenvType == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
     if stdenvType == "i686-mingw" then stdenvMinGW else
     if stdenvType == "i686-darwin" then stdenvNix else
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index bea36088c748..191dd54c6aea 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -45,14 +45,36 @@ let
         mkDerivation = attrs:
           (derivation (
             (removeAttrs attrs ["meta" "passthru"])
-            //
+            // (let
+                buildInputs = if attrs ? buildInputs then attrs.buildInputs
+                    else [];
+                buildNativeInputs = if attrs ? buildNativeInputs then
+                    attrs.buildNativeInputs else [];
+                propagatedBuildInputs = if attrs ? propagatedBuildInputs then
+                    attrs.propagatedBuildInputs else [];
+                propagatedBuildNativeInputs = if attrs ?
+                    propagatedBuildNativeInputs then
+                    attrs.propagatedBuildNativeInputs else [];
+                crossConfig = if (attrs ? crossConfig) then attrs.crossConfig else
+                   null;
+            in
             {
               builder = if attrs ? realBuilder then attrs.realBuilder else shell;
               args = if attrs ? args then attrs.args else
                 ["-e" (if attrs ? builder then attrs.builder else ./default-builder.sh)];
               stdenv = result;
               system = result.system;
-            })
+
+              # That build by the cross compiler
+              buildInputs = lib.optionals (crossConfig != null) buildInputs;
+              propagatedBuildInputs = lib.optionals (crossConfig != null)
+                  propagatedBuildInputs;
+              # That build by the usual native compiler
+              buildNativeInputs = buildNativeInputs ++ lib.optionals
+                (crossConfig == null) buildInputs;
+              propagatedBuildNativeInputs = propagatedBuildNativeInputs ++
+                lib.optionals (crossConfig == null) propagatedBuildInputs;
+            }))
           )
           # The meta attribute is passed in the resulting attribute set,
           # but it's not part of the actual derivation, i.e., it's not
@@ -71,7 +93,8 @@ let
         isDarwin = result.system == "i686-darwin" || result.system == "powerpc-darwin" || result.system == "x86_64-darwin";
         isLinux = result.system == "i686-linux"
                || result.system == "x86_64-linux"
-               || result.system == "powerpc-linux";
+               || result.system == "powerpc-linux"
+               || result.system == "armv5tel-linux";
         isi686 = result.system == "i686-linux"
                || result.system == "i686-darwin"
                || result.system == "i686-freebsd"
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index cadfeadc6dbe..5e2fc7b24dbe 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -4,11 +4,12 @@
 # environment variables) and from shell scripts (as functions). 
 runHook() {
     local hookName="$1"
-    if test "$(type -t $hookName)" = function; then
-        $hookName
-    else
-        eval "${!hookName}"
-    fi
+    case "$(type -t $hookName)" in
+        (function|alias|builtin) $hookName;;
+        (file) source $hookName;;
+        (keyword) :;;
+        (*) eval "${!hookName}";;
+    esac
 }
 
 
@@ -78,6 +79,10 @@ addToSearchPath() {
 
 set -e
 
+# Check that the directory pointed by HOME, usually '/homeless-shelter',
+# does not exist, as it may be a good source for impurities.
+! test -e $HOME
+
 test -z $NIX_GCC && NIX_GCC=@gcc@
 
 
@@ -119,6 +124,7 @@ if test -z "$SHELL"; then echo "SHELL not set"; exit 1; fi
 
 # Hack: run gcc's setup hook.
 envHooks=()
+crossEnvHooks=()
 if test -f $NIX_GCC/nix-support/setup-hook; then
     source $NIX_GCC/nix-support/setup-hook
 fi
@@ -147,35 +153,41 @@ runHook addInputsHook
 # Recursively find all build inputs.
 findInputs() {
     local pkg=$1
+    local var=$2
+    local propagatedBuildInputsFile=$3
 
-    case $pkgs in
+    case ${!var} in
         *\ $pkg\ *)
             return 0
             ;;
     esac
 
-    pkgs="$pkgs $pkg "
+    eval $var="'${!var} $pkg '"
 
     if test -f $pkg/nix-support/setup-hook; then
         source $pkg/nix-support/setup-hook
     fi
 
-    if test -f $pkg/nix-support/propagated-build-inputs; then
-        for i in $(cat $pkg/nix-support/propagated-build-inputs); do
-            findInputs $i
+    if test -f $pkg/nix-support/$propagatedBuildInputsFile; then
+        for i in $(cat $pkg/nix-support/$propagatedBuildInputsFile); do
+            findInputs $i $var $propagatedBuildInputsFile
         done
     fi
 }
 
-pkgs=""
+crossPkgs=""
 for i in $buildInputs $propagatedBuildInputs; do
-    findInputs $i
+    findInputs $i crossPkgs propagated-build-inputs
 done
 
+nativePkgs=""
+for i in $buildNativeInputs $propagatedBuildNativeInputs; do
+    findInputs $i nativePkgs propagated-build-native-inputs
+done
 
 # Set the relevant environment variables to point to the build inputs
 # found above.
-addToEnv() {
+addToNativeEnv() {
     local pkg=$1
 
     if test -d $1/bin; then
@@ -188,8 +200,28 @@ addToEnv() {
     done
 }
 
-for i in $pkgs; do
-    addToEnv $i
+for i in $nativePkgs; do
+    addToNativeEnv $i
+done
+
+addToCrossEnv() {
+    local pkg=$1
+
+    # Some programs put important build scripts (freetype-config and similar)
+    # into their hostDrv bin path. Intentionally these should go after
+    # the nativePkgs in PATH.
+    if test -d $1/bin; then
+        addToSearchPath _PATH $1/bin
+    fi
+
+    # Run the package-specific hooks set by the setup-hook scripts.
+    for i in "${crossEnvHooks[@]}"; do
+        $i $pkg
+    done
+}
+
+for i in $crossPkgs; do
+    addToCrossEnv $i
 done
 
 
@@ -393,15 +425,11 @@ unpackFile() {
     header "unpacking source archive $curSrc" 3
 
     case "$curSrc" in
-        *.tar)
+        *.tar | *.tar.* | *.tgz | *.tbz2)
+	    # GNU tar can automatically select the decompression method
+	    # (info "(tar) gzip").
             tar xvf $curSrc
             ;;
-        *.tar.gz | *.tgz | *.tar.Z)
-            gzip -d < $curSrc | tar xvf -
-            ;;
-        *.tar.bz2 | *.tbz2)
-            bzip2 -d < $curSrc | tar xvf -
-            ;;
         *.zip)
             unzip $curSrc
             ;;
@@ -505,6 +533,9 @@ patchPhase() {
             *.bz2)
                 uncompress="bzip2 -d"
                 ;;
+            *.lzma)
+                uncompress="lzma -d"
+                ;;
         esac
         $uncompress < $i | patch ${patchFlags:--p1}
         stopNest
@@ -692,6 +723,11 @@ fixupPhase() {
         echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
     fi
 
+    if test -n "$propagatedBuildNativeInputs"; then
+        ensureDir "$out/nix-support"
+        echo "$propagatedBuildNativeInputs" > "$out/nix-support/propagated-build-native-inputs"
+    fi
+
     if test -n "$setupHook"; then
         ensureDir "$out/nix-support"
         substituteAll "$setupHook" "$out/nix-support/setup-hook"
diff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/bzip2 b/pkgs/stdenv/linux/bootstrap/armv5tel/bzip2
new file mode 100755
index 000000000000..5c9be292fe8b
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/bzip2
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/cpio b/pkgs/stdenv/linux/bootstrap/armv5tel/cpio
new file mode 100755
index 000000000000..3d69f9e5bd86
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/cpio
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/curl.bz2 b/pkgs/stdenv/linux/bootstrap/armv5tel/curl.bz2
new file mode 100755
index 000000000000..1f2985bd347b
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/curl.bz2
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/default.nix b/pkgs/stdenv/linux/bootstrap/armv5tel/default.nix
new file mode 100644
index 000000000000..3a8a03e5a541
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/default.nix
@@ -0,0 +1,13 @@
+{
+  sh = ./sh;
+  bzip2 = ./bzip2;
+  mkdir = ./mkdir;
+  cpio = ./cpio;
+  ln = ./ln;
+  curl = ./curl.bz2;
+
+  bootstrapTools = {
+    url = "http://nixos.org/tarballs/stdenv-linux/armv5tel/r18744/bootstrap-tools.cpio.bz2";
+    sha256 = "1rn4n5kilqmv62dfjfcscbsm0w329k3gyb2v9155fsi1sl2cfzcb";
+  };
+}
diff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/ln b/pkgs/stdenv/linux/bootstrap/armv5tel/ln
new file mode 100755
index 000000000000..f2c0db164010
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/ln
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/mkdir b/pkgs/stdenv/linux/bootstrap/armv5tel/mkdir
new file mode 100755
index 000000000000..c551673d32a5
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/mkdir
Binary files differdiff --git a/pkgs/stdenv/linux/bootstrap/armv5tel/sh b/pkgs/stdenv/linux/bootstrap/armv5tel/sh
new file mode 100755
index 000000000000..74d82aa94f20
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap/armv5tel/sh
Binary files differdiff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix
index b74258120b3c..dd5647bec456 100644
--- a/pkgs/stdenv/linux/default.nix
+++ b/pkgs/stdenv/linux/default.nix
@@ -13,6 +13,7 @@ rec {
     if system == "i686-linux" then import ./bootstrap/i686
     else if system == "x86_64-linux" then import ./bootstrap/x86_64
     else if system == "powerpc-linux" then import ./bootstrap/powerpc
+    else if system == "armv5tel-linux" then import ./bootstrap/armv5tel
     else abort "unsupported platform for the pure Linux stdenv";
 
 
@@ -50,7 +51,10 @@ rec {
     
     builder = bootstrapFiles.sh;
     
-    args = [ ./scripts/unpack-bootstrap-tools.sh ];
+    args = if (system == "armv5tel-linux") then
+      ([ ./scripts/unpack-bootstrap-tools-arm.sh ])
+      else 
+      ([ ./scripts/unpack-bootstrap-tools.sh ]);
     
     inherit (bootstrapFiles) bzip2 mkdir curl cpio;
     
@@ -89,7 +93,6 @@ rec {
       extraAttrs = extraAttrs // {inherit fetchurl;};
     };
 
-
   # 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 {
@@ -120,12 +123,12 @@ rec {
 
   # A helper function to call gcc-wrapper.
   wrapGCC =
-    {gcc ? bootstrapTools, libc, binutils, shell ? "", name ? "bootstrap-gcc"}:
+    {gcc ? bootstrapTools, libc, binutils, coreutils, shell ? "", name ? "bootstrap-gcc-wrapper"}:
     
     import ../../build-support/gcc-wrapper {
       nativeTools = false;
       nativeLibc = false;
-      inherit gcc binutils libc shell name;
+      inherit gcc binutils coreutils libc shell name;
       stdenv = stdenvLinuxBoot0;
     };
 
@@ -134,7 +137,11 @@ rec {
   # of bootstrap tools only, and a minimal Glibc to keep the GCC
   # configure script happy.
   stdenvLinuxBoot1 = stdenvBootFun {
-    gcc = wrapGCC {libc = bootstrapGlibc; binutils = bootstrapTools;};
+    gcc = wrapGCC {
+      libc = bootstrapGlibc;
+      binutils = bootstrapTools;
+      coreutils = bootstrapTools;
+    };
     inherit fetchurl;
   };
   
@@ -156,8 +163,15 @@ rec {
   #    this one uses the Glibc built in step 3.  It still uses
   #    the rest of the bootstrap tools, including GCC.
   stdenvLinuxBoot2 = removeAttrs (stdenvBootFun {
-    gcc = wrapGCC {binutils = bootstrapTools; libc = stdenvLinuxGlibc;};
-    extraAttrs = {glibc = stdenvLinuxGlibc;};
+    gcc = wrapGCC {
+      binutils = bootstrapTools;
+      coreutils = bootstrapTools;
+      libc = stdenvLinuxGlibc;
+    };
+    extraAttrs = {
+      glibc = stdenvLinuxGlibc;
+      inherit (stdenvLinuxBoot1Pkgs) perl;
+    };
     inherit fetchurl;
   }) ["gcc" "binutils"];
 
@@ -176,10 +190,14 @@ rec {
   stdenvLinuxBoot3 = stdenvBootFun {
     gcc = wrapGCC rec {
       inherit (stdenvLinuxBoot2Pkgs) binutils;
+      coreutils = bootstrapTools;
       libc = stdenvLinuxGlibc;
       gcc = stdenvLinuxBoot2Pkgs.gcc.gcc;
       name = "";
     };
+    extraAttrs = {
+      inherit (stdenvLinuxBoot1Pkgs) perl;
+    };
     inherit fetchurl;
   };
 
@@ -210,6 +228,7 @@ rec {
 
     gcc = wrapGCC rec {
       inherit (stdenvLinuxBoot2Pkgs) binutils;
+      inherit (stdenvLinuxBoot3Pkgs) coreutils;
       libc = stdenvLinuxGlibc;
       gcc = stdenvLinuxBoot2Pkgs.gcc.gcc;
       shell = stdenvLinuxBoot3Pkgs.bash + "/bin/bash";
diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix
index de8a25c6f64c..3f68738c3108 100644
--- a/pkgs/stdenv/linux/make-bootstrap-tools.nix
+++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix
@@ -10,20 +10,26 @@ rec {
     aclSupport = false;
   });
 
+  gccLinkStatic = wrapGCCWith (import ../../build-support/gcc-wrapper) uclibc
+    stdenv.gcc.gcc;
+  stdenvLinkStatic = overrideGCC stdenv gccLinkStatic;
 
-  curlDiet = import ../../tools/networking/curl {
+  curlStatic = import ../../tools/networking/curl {
+    stdenv = stdenvLinkStatic;
     inherit fetchurl;
-    stdenv = useDietLibC stdenv;
     zlibSupport = false;
     sslSupport = false;
+    linkStatic = true;
   };
 
 
-  bzip2Diet = import ../../tools/compression/bzip2 {
+  bzip2Static = import ../../tools/compression/bzip2 {
+    stdenv = stdenvLinkStatic;
     inherit fetchurl;
-    stdenv = useDietLibC stdenv;
+    linkStatic = true;
   };
 
+  #gccNoShared = wrapGCC ( gcc.gcc.override { enableShared = false; } );
 
   build = 
 
@@ -33,6 +39,7 @@ rec {
       buildInputs = [nukeReferences cpio];
 
       buildCommand = ''
+	set -x
         ensureDir $out/bin $out/lib $out/libexec
 
         # Copy what we need of Glibc.
@@ -100,6 +107,8 @@ rec {
 
         cp -d ${gmp}/lib/libgmp*.so* $out/lib
         cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
+        cp -d ${ppl}/lib/libppl*.so* $out/lib
+        cp -d ${cloogppl}/lib/libcloog*.so* $out/lib
         
         # Copy binutils.
         for i in as ld ar ranlib nm strip readelf objdump; do
@@ -132,8 +141,8 @@ rec {
         cp ${klibc}/lib/klibc/bin.static/cpio $out/in-nixpkgs
         cp ${klibc}/lib/klibc/bin.static/mkdir $out/in-nixpkgs
         cp ${klibc}/lib/klibc/bin.static/ln $out/in-nixpkgs
-        cp ${curlDiet}/bin/curl $out/in-nixpkgs
-        cp ${bzip2Diet}/bin/bzip2 $out/in-nixpkgs
+        cp ${curlStatic}/bin/curl $out/in-nixpkgs
+        cp ${bzip2Static}/bin/bzip2 $out/in-nixpkgs
         chmod u+w $out/in-nixpkgs/*
         strip $out/in-nixpkgs/*
         nuke-refs $out/in-nixpkgs/*
diff --git a/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools-arm.sh b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools-arm.sh
new file mode 100644
index 000000000000..3709ac05041b
--- /dev/null
+++ b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools-arm.sh
@@ -0,0 +1,54 @@
+set -e
+
+# Unpack the bootstrap tools tarball.
+echo Unpacking the bootstrap tools...
+$mkdir $out
+$bzip2 -d < $tarball | (cd $out && $cpio -V -i)
+
+# Set the ELF interpreter / RPATH in the bootstrap binaries.
+echo Patching the bootstrap tools...
+
+# On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs.  So
+# use a copy of patchelf.
+LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? $out/bin/cp $out/bin/patchelf .
+
+for i in $out/bin/* $out/libexec/gcc/*/*/* $out/lib/librt*; do
+    echo patching $i
+    if ! test -L $i; then
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+    fi
+done
+for i in $out/lib/libppl* $out/lib/libgmp*; do
+    echo patching $i
+    if ! test -L $i; then
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-rpath $out/lib --force-rpath $i
+    fi
+done
+
+# Fix the libc linker script.
+export PATH=$out/bin
+cat $out/lib/libc.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libc.so.tmp
+mv $out/lib/libc.so.tmp $out/lib/libc.so
+cat $out/lib/libpthread.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libpthread.so.tmp
+mv $out/lib/libpthread.so.tmp $out/lib/libpthread.so
+
+# Provide some additional symlinks.
+ln -s bash $out/bin/sh
+ln -s bzip2 $out/bin/bunzip2
+
+# Mimic the gunzip script as in gzip installations
+cat > $out/bin/gunzip <<EOF
+#!$out/bin/sh
+exec $out/bin/gzip -d "\$@"
+EOF
+chmod +x $out/bin/gunzip
+
+# fetchurl needs curl.
+bzip2 -d < $curl > $out/bin/curl
+chmod +x $out/bin/curl
diff --git a/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
index c1fa8582ed8a..2399e48b026f 100644
--- a/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
+++ b/pkgs/stdenv/linux/scripts/unpack-bootstrap-tools.sh
@@ -10,13 +10,24 @@ echo Patching the bootstrap tools...
 
 # On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs.  So
 # use a copy of patchelf.
-LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.2 $out/bin/cp $out/bin/patchelf .
+LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? $out/bin/cp $out/bin/patchelf .
 
 for i in $out/bin/* $out/libexec/gcc/*/*/*; do
     echo patching $i
     if ! test -L $i; then
-         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.2 \
-             ./patchelf --set-interpreter $out/lib/ld-linux*.so.2 --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+    fi
+done
+for i in $out/lib/librt* ; do
+    echo patching $i
+    if ! test -L $i; then
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
+         LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.? \
+             $out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib --force-rpath $i
     fi
 done
 
@@ -24,12 +35,20 @@ done
 export PATH=$out/bin
 cat $out/lib/libc.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libc.so.tmp
 mv $out/lib/libc.so.tmp $out/lib/libc.so
+cat $out/lib/libpthread.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libpthread.so.tmp
+mv $out/lib/libpthread.so.tmp $out/lib/libpthread.so
 
 # Provide some additional symlinks.
 ln -s bash $out/bin/sh
-
 ln -s bzip2 $out/bin/bunzip2
 
+# Mimic the gunzip script as in gzip installations
+cat > $out/bin/gunzip <<EOF
+#!$out/bin/sh
+exec $out/bin/gzip -d "\$@"
+EOF
+chmod +x $out/bin/gunzip
+
 # fetchurl needs curl.
 bzip2 -d < $curl > $out/bin/curl
 chmod +x $out/bin/curl
diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix
index 521f381eed25..5b1b2af8285f 100644
--- a/pkgs/stdenv/nix/default.nix
+++ b/pkgs/stdenv/nix/default.nix
@@ -17,6 +17,7 @@ import ../generic {
       else
         pkgs.binutils;
     gcc = if stdenv.isDarwin then pkgs.gccApple.gcc else pkgs.gcc.gcc;
+    coreutils = pkgs.coreutils;
     shell = pkgs.bash + "/bin/sh";
   };