Skip to content

Commit

Permalink
Merge pull request #12453 from NixOS/mergify/bp/2.26-maintenance/pr-1…
Browse files Browse the repository at this point in the history
…2448

copyPathToStore(): Preserve symlinks (backport #12448)
  • Loading branch information
edolstra authored Feb 11, 2025
2 parents 4c3786d + 83306bb commit dfbd030
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,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,
Expand Down
1 change: 1 addition & 0 deletions tests/functional/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ suites = [
'debugger.sh',
'extra-sandbox-profile.sh',
'help.sh',
'symlinks.sh',
],
'workdir': meson.current_source_dir(),
},
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions tests/functional/symlinks.sh
Original file line number Diff line number Diff line change
@@ -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;
}
'

0 comments on commit dfbd030

Please sign in to comment.