summary refs log tree commit diff
path: root/nixos/modules/system/boot/stage-1.nix
diff options
context:
space:
mode:
authorWilliam A. Kennington III <william@wkennington.com>2015-03-29 21:53:25 -0700
committerWilliam A. Kennington III <william@wkennington.com>2015-03-29 21:53:25 -0700
commit113c6c8f6a5be89dd8aee845a04a5e713e285d4c (patch)
tree037ca1aac606168ef27f360e8f6652cd04bcc779 /nixos/modules/system/boot/stage-1.nix
parent6b3cf366d7a6f660797b171fe9339f0ca9576632 (diff)
downloadnixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar.gz
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar.bz2
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar.lz
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar.xz
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.tar.zst
nixpkgs-113c6c8f6a5be89dd8aee845a04a5e713e285d4c.zip
nixos/initrd: Do a lazy library copy in hopes to save some space for replaced binaries
Diffstat (limited to 'nixos/modules/system/boot/stage-1.nix')
-rw-r--r--nixos/modules/system/boot/stage-1.nix38
1 files changed, 21 insertions, 17 deletions
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index 47d6dd2bf54..8b58eccdcec 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -39,26 +39,9 @@ let
       mkdir -p $out/bin $out/lib
       ln -s $out/bin $out/sbin
 
-      # Copy ld manually since it isn't detected correctly
-      cp -pv ${pkgs.glibc}/lib/ld*.so.? $out/lib
-
       copy_bin_and_libs () {
         [ -f "$out/bin/$(basename $1)" ] && rm "$out/bin/$(basename $1)"
         cp -pdv $1 $out/bin
-        LDD="$(ldd $1)" || return 0
-        LIBS="$(echo "$LDD" | awk '{print $3}' | sed '/^$/d')"
-        for LIB in $LIBS; do
-          [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
-          while [ "$(readlink $LIB)" != "" ]; do
-            LINK="$(readlink $LIB)"
-            if [ "${LINK:0:1}" != "/" ]; then
-              LINK="$(dirname $LIB)/$LINK"
-            fi
-            LIB="$LINK"
-            [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
-          done
-        done
-        return 0
       }
 
       # Copy BusyBox.
@@ -89,6 +72,27 @@ let
 
       ${config.boot.initrd.extraUtilsCommands}
 
+      # Copy ld manually since it isn't detected correctly
+      cp -pv ${pkgs.glibc}/lib/ld*.so.? $out/lib
+
+      # Copy all of the needed libraries for the binaries
+      for BIN in $(find $out/{bin,sbin} -type f); do
+        echo "Copying libs for bin $BIN"
+        LDD="$(ldd $BIN)" || continue
+        LIBS="$(echo "$LDD" | awk '{print $3}' | sed '/^$/d')"
+        for LIB in $LIBS; do
+          [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
+          while [ "$(readlink $LIB)" != "" ]; do
+            LINK="$(readlink $LIB)"
+            if [ "${LINK:0:1}" != "/" ]; then
+              LINK="$(dirname $LIB)/$LINK"
+            fi
+            LIB="$LINK"
+            [ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
+          done
+        done
+      done
+
       # Strip binaries further than normal.
       chmod -R u+w $out
       stripDirs "lib bin" "-s"