1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-03 02:01:48 +02:00

lockFlake(): When refetching a locked flake, use the locked ref

Otherwise we may accidentally update a lock when we shouldn't.

Fixes #12445.

(cherry picked from commit 5c552b62fc)

# Conflicts:
#	src/libflake/flake/flake.cc
This commit is contained in:
Eelco Dolstra 2025-02-12 14:53:04 +01:00 committed by Mergify
parent 49f226e87b
commit dffcc184d7

View file

@ -554,12 +554,18 @@ LockedFlake lockFlake(
/* Get the input flake, resolve 'path:./...' /* Get the input flake, resolve 'path:./...'
flakerefs relative to the parent flake. */ flakerefs relative to the parent flake. */
auto getInputFlake = [&]() auto getInputFlake = [&](const FlakeRef & ref)
{ {
if (auto resolvedPath = resolveRelativePath()) { if (auto resolvedPath = resolveRelativePath()) {
<<<<<<< HEAD
return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputPath); return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputPath);
} else { } else {
return getFlake(state, *input.ref, useRegistries, flakeCache, inputPath); return getFlake(state, *input.ref, useRegistries, flakeCache, inputPath);
=======
return readFlake(state, ref, ref, ref, *resolvedPath, inputAttrPath);
} else {
return getFlake(state, ref, useRegistries, flakeCache, inputAttrPath);
>>>>>>> 5c552b62f (lockFlake(): When refetching a locked flake, use the locked ref)
} }
}; };
@ -640,7 +646,7 @@ LockedFlake lockFlake(
} }
if (mustRefetch) { if (mustRefetch) {
auto inputFlake = getInputFlake(); auto inputFlake = getInputFlake(oldLock->lockedRef);
nodePaths.emplace(childNode, inputFlake.path.parent()); nodePaths.emplace(childNode, inputFlake.path.parent());
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, followsPrefix, computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, followsPrefix,
inputFlake.path, false); inputFlake.path, false);
@ -668,7 +674,7 @@ LockedFlake lockFlake(
auto ref = (input2.ref && explicitCliOverrides.contains(inputPath)) ? *input2.ref : *input.ref; auto ref = (input2.ref && explicitCliOverrides.contains(inputPath)) ? *input2.ref : *input.ref;
if (input.isFlake) { if (input.isFlake) {
auto inputFlake = getInputFlake(); auto inputFlake = getInputFlake(*input.ref);
auto childNode = make_ref<LockedNode>( auto childNode = make_ref<LockedNode>(
inputFlake.lockedRef, inputFlake.lockedRef,