Skip to content

Commit 7edc95d

Browse files
Fix "follows" paths in subordinate lockfiles
1 parent 8127094 commit 7edc95d

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/libexpr/flake/flake.cc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,18 @@ LockedFlake lockFlake(
321321
const FlakeInputs & flakeInputs,
322322
std::shared_ptr<Node> node,
323323
const InputPath & inputPathPrefix,
324-
std::shared_ptr<const Node> oldNode)>
324+
std::shared_ptr<const Node> oldNode,
325+
const bool relative, const int relativeDepth)>
325326
computeLocks;
326327

327328
computeLocks = [&](
328329
const FlakeInputs & flakeInputs,
329330
std::shared_ptr<Node> node,
330331
const InputPath & inputPathPrefix,
331-
std::shared_ptr<const Node> oldNode)
332+
std::shared_ptr<const Node> oldNode,
333+
const bool relative, const int relativeDepth)
332334
{
333-
debug("computing lock file node '%s'", printInputPath(inputPathPrefix));
335+
debug("computing lock file node '%s' (depth %i)", printInputPath(inputPathPrefix), relativeDepth);
334336

335337
/* Get the overrides (i.e. attributes of the form
336338
'inputs.nixops.inputs.nixpkgs.url = ...'). */
@@ -366,11 +368,20 @@ LockedFlake lockFlake(
366368
path we haven't processed yet. */
367369
if (input.follows) {
368370
InputPath target;
369-
if (hasOverride || input.absolute)
371+
if (hasOverride || input.absolute) {
370372
/* 'follows' from an override is relative to the
371-
root of the graph. */
372-
target = *input.follows;
373-
else {
373+
root of the graph, but we need to fix up the path for subordinate lockfiles */
374+
if (relative) {
375+
target = nix::flake::InputPath();
376+
377+
// special case for the root of the subordinate - we need to pop once
378+
if (!relativeDepth) target.pop_back();
379+
for (int i = 0; i < relativeDepth; i++) target.pop_back();
380+
for (auto & i : *input.follows) target.push_back(i);
381+
} else {
382+
target = *input.follows;
383+
}
384+
} else {
374385
/* Otherwise, it's relative to the current flake. */
375386
target = inputPathPrefix;
376387
for (auto & i : *input.follows) target.push_back(i);
@@ -420,7 +431,7 @@ LockedFlake lockFlake(
420431
if (hasChildUpdate) {
421432
auto inputFlake = getFlake(
422433
state, oldLock->lockedRef, false, flakeCache);
423-
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock);
434+
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, relative, relativeDepth + 1);
424435
} else {
425436
/* No need to fetch this flake, we can be
426437
lazy. However there may be new overrides on the
@@ -442,7 +453,7 @@ LockedFlake lockFlake(
442453
}
443454
}
444455

445-
computeLocks(fakeInputs, childNode, inputPath, oldLock);
456+
computeLocks(fakeInputs, childNode, inputPath, oldLock, relative, relativeDepth + 1);
446457
}
447458

448459
} else {
@@ -484,7 +495,8 @@ LockedFlake lockFlake(
484495
oldLock
485496
? std::dynamic_pointer_cast<const Node>(oldLock)
486497
: LockFile::read(
487-
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root);
498+
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root,
499+
!oldLock, 0);
488500
}
489501

490502
else {
@@ -504,7 +516,7 @@ LockedFlake lockFlake(
504516

505517
computeLocks(
506518
flake.inputs, newLockFile.root, {},
507-
lockFlags.recreateLockFile ? nullptr : oldLockFile.root);
519+
lockFlags.recreateLockFile ? nullptr : oldLockFile.root, false, 0);
508520

509521
for (auto & i : lockFlags.inputOverrides)
510522
if (!overridesUsed.count(i.first))

0 commit comments

Comments
 (0)