mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 06:45:16 +01:00
nixos/initrd: Do a lazy library copy in hopes to save some space for replaced binaries
This commit is contained in:
parent
6b3cf366d7
commit
113c6c8f6a
1 changed files with 21 additions and 17 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue