Skip to content

Commit 26b87e7

Browse files
committed
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.
1 parent 92bf150 commit 26b87e7

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/libexpr/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
23842384
: [&]() {
23852385
auto dstPath = fetchToStore(
23862386
*store,
2387-
path.resolveSymlinks(),
2387+
path.resolveSymlinks(SymlinkResolution::Ancestors),
23882388
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
23892389
path.baseName(),
23902390
ContentAddressMethod::Raw::NixArchive,

tests/functional/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ suites = [
164164
'debugger.sh',
165165
'extra-sandbox-profile.sh',
166166
'help.sh',
167+
'symlinks.sh',
167168
],
168169
'workdir': meson.current_source_dir(),
169170
},

tests/functional/simple.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ echo "output path is $outPath"
1515
[[ ! -w $outPath ]]
1616

1717
text=$(cat "$outPath/hello")
18-
if test "$text" != "Hello World!"; then exit 1; fi
18+
[[ "$text" = "Hello World!" ]]
1919

2020
TODO_NixOS
2121

tests/functional/symlinks.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
5+
# Check that when we have a derivation attribute that refers to a
6+
# symlink, we copy the symlink, not its target.
7+
# shellcheck disable=SC2016
8+
nix build --impure --no-link --expr '
9+
with import ./config.nix;
10+
11+
mkDerivation {
12+
name = "simple";
13+
builder = builtins.toFile "builder.sh" "[[ -L \"$symlink\" ]]; mkdir $out";
14+
symlink = ./lang/symlink-resolution/foo/overlays;
15+
}
16+
'

0 commit comments

Comments
 (0)