Skip to content

Commit 045f511

Browse files
Fix "follows" paths in subordinate lockfiles
1 parent 8127094 commit 045f511

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/libexpr/flake/flake.cc

Lines changed: 20 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,17 @@ 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 = inputPathPrefix;
376+
for (int i = 0; i < relativeDepth; i++) target.pop_back();
377+
for (auto & i : *input.follows) target.push_back(i);
378+
} else {
379+
target = *input.follows;
380+
}
381+
} else {
374382
/* Otherwise, it's relative to the current flake. */
375383
target = inputPathPrefix;
376384
for (auto & i : *input.follows) target.push_back(i);
@@ -420,7 +428,7 @@ LockedFlake lockFlake(
420428
if (hasChildUpdate) {
421429
auto inputFlake = getFlake(
422430
state, oldLock->lockedRef, false, flakeCache);
423-
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock);
431+
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, relative, relativeDepth + 1);
424432
} else {
425433
/* No need to fetch this flake, we can be
426434
lazy. However there may be new overrides on the
@@ -442,7 +450,7 @@ LockedFlake lockFlake(
442450
}
443451
}
444452

445-
computeLocks(fakeInputs, childNode, inputPath, oldLock);
453+
computeLocks(fakeInputs, childNode, inputPath, oldLock, relative, relativeDepth + 1);
446454
}
447455

448456
} else {
@@ -484,7 +492,8 @@ LockedFlake lockFlake(
484492
oldLock
485493
? std::dynamic_pointer_cast<const Node>(oldLock)
486494
: LockFile::read(
487-
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root);
495+
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root,
496+
!oldLock, relativeDepth);
488497
}
489498

490499
else {
@@ -504,7 +513,7 @@ LockedFlake lockFlake(
504513

505514
computeLocks(
506515
flake.inputs, newLockFile.root, {},
507-
lockFlags.recreateLockFile ? nullptr : oldLockFile.root);
516+
lockFlags.recreateLockFile ? nullptr : oldLockFile.root, false, 0);
508517

509518
for (auto & i : lockFlags.inputOverrides)
510519
if (!overridesUsed.count(i.first))

0 commit comments

Comments
 (0)