1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-12 23:15:08 +02:00

Merge pull request #13439 from NixOS/mergify/bp/2.30-maintenance/pr-13437

lockFlake(): When updating a lock, respect the input's lock file (backport #13437)
This commit is contained in:
tomberek 2025-07-10 01:03:55 -04:00 committed by GitHub
commit f880135ff8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 7 deletions

View file

@ -715,16 +715,12 @@ LockedFlake lockFlake(
Finally cleanup([&]() { parents.pop_back(); });
/* Recursively process the inputs of this
flake. Also, unless we already have this flake
in the top-level lock file, use this flake's
own lock file. */
flake, using its own lock file. */
nodePaths.emplace(childNode, inputFlake.path.parent());
computeLocks(
inputFlake.inputs, childNode, inputAttrPath,
oldLock
? std::dynamic_pointer_cast<const Node>(oldLock)
: readLockFile(state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(),
oldLock ? followsPrefix : inputAttrPath,
readLockFile(state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(),
inputAttrPath,
inputFlake.path,
false);
}

View file

@ -432,3 +432,41 @@ nix flake metadata "$flake2Dir" --reference-lock-file $TEST_ROOT/flake2-overridd
# reference-lock-file can only be used if allow-dirty is set.
expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock-file $TEST_ROOT/flake2-overridden.lock
# After changing an input (flake2 from newFlake2Rev to prevFlake2Rev), we should have the transitive inputs locked by revision $prevFlake2Rev of flake2.
prevFlake1Rev=$(nix flake metadata --json "$flake1Dir" | jq -r .revision)
prevFlake2Rev=$(nix flake metadata --json "$flake2Dir" | jq -r .revision)
echo "# bla" >> "$flake1Dir/flake.nix"
git -C "$flake1Dir" commit flake.nix -m 'bla'
nix flake update --flake "$flake2Dir"
git -C "$flake2Dir" commit flake.lock -m 'bla'
newFlake1Rev=$(nix flake metadata --json "$flake1Dir" | jq -r .revision)
newFlake2Rev=$(nix flake metadata --json "$flake2Dir" | jq -r .revision)
cat > "$flake3Dir/flake.nix" <<EOF
{
inputs.flake2.url = "flake:flake2/master/$newFlake2Rev";
outputs = { self, flake2 }: {
};
}
EOF
git -C "$flake3Dir" commit flake.nix -m 'bla'
rm "$flake3Dir/flake.lock"
nix flake lock "$flake3Dir"
[[ "$(nix flake metadata --json "$flake3Dir" | jq -r .locks.nodes.flake1.locked.rev)" = $newFlake1Rev ]]
cat > "$flake3Dir/flake.nix" <<EOF
{
inputs.flake2.url = "flake:flake2/master/$prevFlake2Rev";
outputs = { self, flake2 }: {
};
}
EOF
[[ "$(nix flake metadata --json "$flake3Dir" | jq -r .locks.nodes.flake1.locked.rev)" = $prevFlake1Rev ]]