···
# mounting `/`, like `/` on a loopback).
fileSystems = filter utils.fsNeededForBoot config.system.build.fileSystems;
+
# A utility for enumerating the shared-library dependencies of a program
+
findLibs = pkgs.writeShellScriptBin "find-libs" ''
+
patchelf="${pkgs.buildPackages.patchelf}/bin/patchelf"
+
rpath="$($patchelf --print-rpath $1)"
+
for lib in $($patchelf --print-needed $1); do
+
left+=("$lib" "$rpath" "$dir")
+
while [ ''${#left[@]} -ne 0 ]; do
+
left=("''${left[@]:3}")
+
if [ -z ''${seen[$next]+x} ]; then
+
IFS=: read -ra paths <<< $rpath
+
for path in "''${paths[@]}"; do
+
path=$(eval "echo $path")
+
if [ -f "$path/$next" ]; then
+
echo "Couldn't satisfy dependency $next" >&2
# Some additional utilities needed in stage 1, like mount, lvm, fsck
# etc. We don't want to bring in all of those packages, so we just
···
# Copy all of the needed libraries
find $out/bin $out/lib -type f | while read BIN; do
echo "Copying libs for executable $BIN"
+
for LIB in $(${findLibs}/bin/find-libs $BIN); do
TGT="$out/lib/$(basename $LIB)"
SRC="$(readlink -e $LIB)"