From 4ea5cb38325c728bb8f96f57b185f3c25275b3a0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 May 2025 17:27:05 +0200 Subject: [PATCH] Fix emitting narHash in lock files when lazy trees are disabled --- src/libexpr/paths.cc | 2 +- tests/functional/fetchGit.sh | 2 +- tests/functional/flakes/flakes.sh | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libexpr/paths.cc b/src/libexpr/paths.cc index da1408e9b..3aaca2328 100644 --- a/src/libexpr/paths.cc +++ b/src/libexpr/paths.cc @@ -77,7 +77,7 @@ StorePath EvalState::mountInput( storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor); - if (requireLockable && !input.isLocked() && !input.getNarHash()) { + if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash()) { auto narHash = accessor->hashPath(CanonPath::root); input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true)); } diff --git a/tests/functional/fetchGit.sh b/tests/functional/fetchGit.sh index 6fc8ca8b0..5e5e8e61f 100755 --- a/tests/functional/fetchGit.sh +++ b/tests/functional/fetchGit.sh @@ -292,7 +292,7 @@ path11=$(nix eval --impure --raw --expr "(builtins.fetchGit ./.).outPath") empty="$TEST_ROOT/empty" git init "$empty" -emptyAttrs='{ lastModified = 0; lastModifiedDate = "19700101000000"; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }' +emptyAttrs='{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }' [[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = $emptyAttrs ]] diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 7ec438d74..fd31c4c4f 100755 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -161,6 +161,7 @@ expect 1 nix build -o "$TEST_ROOT/result" "$flake2Dir#bar" --no-update-lock-file nix build -o "$TEST_ROOT/result" "$flake2Dir#bar" --commit-lock-file [[ -e "$flake2Dir/flake.lock" ]] [[ -z $(git -C "$flake2Dir" diff main || echo failed) ]] +[[ -n $(jq .nodes.flake1.locked.narHash < "$flake2Dir/flake.lock") ]] # Rerunning the build should not change the lockfile. nix build -o "$TEST_ROOT/result" "$flake2Dir#bar"