nixpkgs/pkgs/build-support/setup-hooks/make-symlinks-relative.sh
Artturin ba11c6f123 setup-hooks/make-symlinks-relative.sh: match what other hooks do so
the hook doesn't output the following if $prefix doesn't exist

find: '/nix/store/...': No such file or directory

some other hooks that do this: prune-libtool-files.sh, audit-tmpdir.sh separate-debug-info.sh
2023-01-06 18:56:54 +02:00

29 lines
910 B
Bash

postFixupHooks+=(_makeSymlinksRelative)
# For every symlink in $output that refers to another file in $output
# ensure that the symlink is relative. This removes references to the output
# has from the resulting store paths and thus the NAR files.
_makeSymlinksRelative() {
local symlinkTarget
if [ "${dontRewriteSymlinks-}" ] || [ ! -e "$prefix" ]; then
return
fi
while IFS= read -r -d $'\0' f; do
symlinkTarget=$(readlink "$f")
if [[ "$symlinkTarget"/ != "$prefix"/* ]]; then
# skip this symlink as it doesn't point to $prefix
continue
fi
if [ ! -e "$symlinkTarget" ]; then
echo "the symlink $f is broken, it points to $symlinkTarget (which is missing)"
fi
echo "rewriting symlink $f to be relative to $prefix"
ln -snrf "$symlinkTarget" "$f"
done < <(find $prefix -type l -print0)
}