From 7bfd71e10d6e441681aacb265d690a4ede584b18 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Feb 2025 20:36:28 +0100 Subject: [PATCH 1/3] copyPathToStore(): Preserve symlinks E.g. in a derivation attribute `foo = ./bar`, if ./bar is a symlink, we should copy the symlink to the store, not its target. This restores the behaviour of Nix <= 2.19. (cherry picked from commit 26b87e78b5dd62d9cca7c7d08a697dd2d22ae38c) --- src/libexpr/eval.cc | 2 +- tests/functional/meson.build | 1 + tests/functional/simple.sh | 2 +- tests/functional/symlinks.sh | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/functional/symlinks.sh diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index da5b2205706..d27e07f01e1 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2365,7 +2365,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat : [&]() { auto dstPath = fetchToStore( *store, - path.resolveSymlinks(), + path.resolveSymlinks(SymlinkResolution::Ancestors), settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy, path.baseName(), ContentAddressMethod::Raw::NixArchive, diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 0d46f9ce219..7c9c694e7d8 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -168,6 +168,7 @@ suites = [ 'debugger.sh', 'extra-sandbox-profile.sh', 'help.sh', + 'symlinks.sh', ], 'workdir': meson.current_source_dir(), }, diff --git a/tests/functional/simple.sh b/tests/functional/simple.sh index 8afa369c2e2..c1f2eef411e 100755 --- a/tests/functional/simple.sh +++ b/tests/functional/simple.sh @@ -15,7 +15,7 @@ echo "output path is $outPath" [[ ! -w $outPath ]] text=$(cat "$outPath/hello") -if test "$text" != "Hello World!"; then exit 1; fi +[[ "$text" = "Hello World!" ]] TODO_NixOS diff --git a/tests/functional/symlinks.sh b/tests/functional/symlinks.sh new file mode 100644 index 00000000000..5eb22b3f901 --- /dev/null +++ b/tests/functional/symlinks.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +source common.sh + +# Check that when we have a derivation attribute that refers to a +# symlink, we copy the symlink, not its target. +# shellcheck disable=SC2016 +nix build --impure --no-link --expr ' + with import ./config.nix; + + mkDerivation { + name = "simple"; + builder = builtins.toFile "builder.sh" "[[ -L \"$symlink\" ]]; mkdir $out"; + symlink = ./lang/symlink-resolution/foo/overlays; + } +' From d856328ab5b8f165a454c226c4330fcef76bf7f9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 12 Feb 2025 20:04:48 +0100 Subject: [PATCH 2/3] Fix build --- tests/functional/meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 7c9c694e7d8..0d46f9ce219 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -168,7 +168,6 @@ suites = [ 'debugger.sh', 'extra-sandbox-profile.sh', 'help.sh', - 'symlinks.sh', ], 'workdir': meson.current_source_dir(), }, From 4aba8ad0225e217c9234acd97fb244586a6d6a5c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 12 Feb 2025 20:05:02 +0100 Subject: [PATCH 3/3] Delete unused test --- tests/functional/symlinks.sh | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 tests/functional/symlinks.sh diff --git a/tests/functional/symlinks.sh b/tests/functional/symlinks.sh deleted file mode 100644 index 5eb22b3f901..00000000000 --- a/tests/functional/symlinks.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -source common.sh - -# Check that when we have a derivation attribute that refers to a -# symlink, we copy the symlink, not its target. -# shellcheck disable=SC2016 -nix build --impure --no-link --expr ' - with import ./config.nix; - - mkDerivation { - name = "simple"; - builder = builtins.toFile "builder.sh" "[[ -L \"$symlink\" ]]; mkdir $out"; - symlink = ./lang/symlink-resolution/foo/overlays; - } -'