From 113c6c8f6a5be89dd8aee845a04a5e713e285d4c Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Sun, 29 Mar 2015 21:53:25 -0700 Subject: [PATCH] nixos/initrd: Do a lazy library copy in hopes to save some space for replaced binaries --- nixos/modules/system/boot/stage-1.nix | 38 +++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 47d6dd2bf54b..8b58eccdcec7 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"