summary refs log tree commit diff
path: root/pkgs/stdenv/linux/bootstrap-tools
diff options
context:
space:
mode:
authorJohn Ericson <jericson@galois.com>2016-12-15 17:09:29 -0500
committerJohn Ericson <jericson@galois.com>2016-12-15 17:09:29 -0500
commit7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd (patch)
tree482c745af3a462d5c216197d0c64c8c6f6cc7b9a /pkgs/stdenv/linux/bootstrap-tools
parent670256dc399ab637fa94df9a90fb13f275c39f8a (diff)
downloadnixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar.gz
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar.bz2
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar.lz
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar.xz
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.tar.zst
nixpkgs-7960a1b1b8fa1ca097bee2971fbbc18bda3dcadd.zip
linux stdenv: Avoid `assert false`
On one hand, don't want to pass garbage that affects hash, on the other
hand footguns are bad.

Now, factored out the derivation so only need to pass in what is used.
Diffstat (limited to 'pkgs/stdenv/linux/bootstrap-tools')
-rw-r--r--pkgs/stdenv/linux/bootstrap-tools/default.nix18
-rw-r--r--pkgs/stdenv/linux/bootstrap-tools/scripts/unpack-bootstrap-tools.sh63
2 files changed, 81 insertions, 0 deletions
diff --git a/pkgs/stdenv/linux/bootstrap-tools/default.nix b/pkgs/stdenv/linux/bootstrap-tools/default.nix
new file mode 100644
index 00000000000..6118585d545
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap-tools/default.nix
@@ -0,0 +1,18 @@
+{ system, bootstrapFiles }:
+
+derivation {
+  name = "bootstrap-tools";
+
+  builder = bootstrapFiles.busybox;
+
+  args = [ "ash" "-e" ./scripts/unpack-bootstrap-tools.sh ];
+
+  tarball = bootstrapFiles.bootstrapTools;
+
+  inherit system;
+
+  # Needed by the GCC wrapper.
+  langC = true;
+  langCC = true;
+  isGNU = true;
+}
diff --git a/pkgs/stdenv/linux/bootstrap-tools/scripts/unpack-bootstrap-tools.sh b/pkgs/stdenv/linux/bootstrap-tools/scripts/unpack-bootstrap-tools.sh
new file mode 100644
index 00000000000..85e74aea89e
--- /dev/null
+++ b/pkgs/stdenv/linux/bootstrap-tools/scripts/unpack-bootstrap-tools.sh
@@ -0,0 +1,63 @@
+# Unpack the bootstrap tools tarball.
+echo Unpacking the bootstrap tools...
+$builder mkdir $out
+< $tarball $builder unxz | $builder tar x -C $out
+
+# Set the ELF interpreter / RPATH in the bootstrap binaries.
+echo Patching the bootstrap tools...
+
+if test -f $out/lib/ld.so.?; then
+   # MIPS case
+   LD_BINARY=$out/lib/ld.so.?
+else
+   # i686, x86_64 and armv5tel
+   LD_BINARY=$out/lib/ld-*so.?
+fi
+
+# 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 $LD_BINARY $out/bin/cp $out/bin/patchelf .
+
+for i in $out/bin/* $out/libexec/gcc/*/*/*; do
+    if [ -L "$i" ]; then continue; fi
+    if [ -z "${i##*/liblto*}" ]; then continue; fi
+    echo patching "$i"
+    LD_LIBRARY_PATH=$out/lib $LD_BINARY \
+        ./patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath "$i"
+done
+
+for i in $out/lib/librt-*.so $out/lib/libpcre*; do
+    if [ -L "$i" ]; then continue; fi
+    echo patching "$i"
+    $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
+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
+
+# Provide a gunzip script.
+cat > $out/bin/gunzip <<EOF
+#!$out/bin/sh
+exec $out/bin/gzip -d "\$@"
+EOF
+chmod +x $out/bin/gunzip
+
+# Provide fgrep/egrep.
+echo "#! $out/bin/sh" > $out/bin/egrep
+echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
+echo "#! $out/bin/sh" > $out/bin/fgrep
+echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
+
+# Provide xz (actually only xz -d will work).
+echo "#! $out/bin/sh" > $out/bin/xz
+echo "exec $builder unxz \"\$@\"" >> $out/bin/xz
+
+chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/xz