mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-30 17:43:42 +00:00
cb007e69a1
While looking at the graph of all the outputs in my personal binary cache it became obvious that we have a lot of self references within the package set. That isn't an isuse by itself. However it increases the size of the binary cache for every (reproducible) build of a package that carries references to itself. You can no longer deduplicate the outputs since they are all unique. One of the ways to get rid of (a few) references is to rewrite all the symlinks that are currently used to be relative symlinks. Two build of something that didn't really change but carries a self-reference can the be store as the same NAR file again. I quickly hacked together this change to see if that would yield and success. My bash scripting skills are probably not great but so far it seem to somewhat work.
29 lines
896 B
Bash
29 lines
896 B
Bash
fixupOutputHooks+=(_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 [ -n "${dontRewriteSymlinks-}" ]; then
|
|
return 0
|
|
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)
|
|
}
|