nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# symlinks are often created in postFixup
2# don't use fixupOutputHooks, it is before postFixup
3if [[ -z "${dontRewriteSymlinks-}" ]]; then
4 postFixupHooks+=(_makeSymlinksRelative)
5fi
6
7
8# For every symlink in $output that refers to another file in $output
9# ensure that the symlink is relative.
10# This increases the chance that NAR files can be deduplicated.
11_makeSymlinksRelative() {
12 local prefixes
13 prefixes=()
14 for output in $(getAllOutputNames); do
15 [ ! -e "${!output}" ] && continue
16 prefixes+=( "${!output}" )
17 done
18 find "${prefixes[@]}" -type l -printf '%H\0%p\0' \
19 | xargs -0 -n2 -r -P "$NIX_BUILD_CORES" sh -c '
20 output="$1"
21 link="$2"
22
23 linkTarget=$(readlink "$link")
24
25 # only touch links that point inside the same output tree
26 [[ $linkTarget == "$output"/* ]] || exit 0
27
28 if [ ! -e "$linkTarget" ]; then
29 echo "the symlink $link is broken, it points to $linkTarget (which is missing)"
30 fi
31
32 echo "making symlink relative: $link"
33 ln -snrf "$linkTarget" "$link"
34 ' _
35}