From 34539b291caac26d1c4f944682f54ea0affd37cf Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Wed, 22 Jan 2025 16:05:17 -0800 Subject: [PATCH] no-broken-symlinks: actually interpolate relative paths --- pkgs/build-support/setup-hooks/no-broken-symlinks.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/setup-hooks/no-broken-symlinks.sh b/pkgs/build-support/setup-hooks/no-broken-symlinks.sh index d622322a2747f..e4acaa1ec1149 100644 --- a/pkgs/build-support/setup-hooks/no-broken-symlinks.sh +++ b/pkgs/build-support/setup-hooks/no-broken-symlinks.sh @@ -40,14 +40,9 @@ noBrokenSymlinks() { nixInfoLog "symlink $path points to absolute target $symlinkTarget" else nixInfoLog "symlink $path points to relative target $symlinkTarget" - symlinkTarget="$pathParent/$symlinkTarget" - - # Check to make sure the interpolated target doesn't escape the store path of `output`. - # If it does, Nix probably won't be able to resolve or track dependencies. - if [[ $symlinkTarget != "$output" && $symlinkTarget != "$output"/* ]]; then - nixErrorLog "symlink $path points to target $symlinkTarget, which escapes the current store path $output" - exit 1 - fi + # Use --no-symlinks to avoid dereferencing again and --canonicalize-missing to avoid existence + # checks at this step (which can lead to infinite recursion). + symlinkTarget="$(realpath --no-symlinks --canonicalize-missing "$pathParent/$symlinkTarget")" fi if [[ $path == "$symlinkTarget" ]]; then