@@ -321,16 +321,18 @@ LockedFlake lockFlake(
321
321
const FlakeInputs & flakeInputs,
322
322
std::shared_ptr<Node> node,
323
323
const InputPath & inputPathPrefix,
324
- std::shared_ptr<const Node> oldNode)>
324
+ std::shared_ptr<const Node> oldNode,
325
+ const bool relative, const int relativeDepth)>
325
326
computeLocks;
326
327
327
328
computeLocks = [&](
328
329
const FlakeInputs & flakeInputs,
329
330
std::shared_ptr<Node> node,
330
331
const InputPath & inputPathPrefix,
331
- std::shared_ptr<const Node> oldNode)
332
+ std::shared_ptr<const Node> oldNode,
333
+ const bool relative, const int relativeDepth)
332
334
{
333
- debug (" computing lock file node '%s'" , printInputPath (inputPathPrefix));
335
+ debug (" computing lock file node '%s' (depth %i) " , printInputPath (inputPathPrefix), relativeDepth );
334
336
335
337
/* Get the overrides (i.e. attributes of the form
336
338
'inputs.nixops.inputs.nixpkgs.url = ...'). */
@@ -366,11 +368,17 @@ LockedFlake lockFlake(
366
368
path we haven't processed yet. */
367
369
if (input.follows ) {
368
370
InputPath target;
369
- if (hasOverride || input.absolute )
371
+ if (hasOverride || input.absolute ) {
370
372
/* '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 {
374
382
/* Otherwise, it's relative to the current flake. */
375
383
target = inputPathPrefix;
376
384
for (auto & i : *input.follows ) target.push_back (i);
@@ -420,7 +428,7 @@ LockedFlake lockFlake(
420
428
if (hasChildUpdate) {
421
429
auto inputFlake = getFlake (
422
430
state, oldLock->lockedRef , false , flakeCache);
423
- computeLocks (inputFlake.inputs , childNode, inputPath, oldLock);
431
+ computeLocks (inputFlake.inputs , childNode, inputPath, oldLock, relative, relativeDepth + 1 );
424
432
} else {
425
433
/* No need to fetch this flake, we can be
426
434
lazy. However there may be new overrides on the
@@ -442,7 +450,7 @@ LockedFlake lockFlake(
442
450
}
443
451
}
444
452
445
- computeLocks (fakeInputs, childNode, inputPath, oldLock);
453
+ computeLocks (fakeInputs, childNode, inputPath, oldLock, relative, relativeDepth + 1 );
446
454
}
447
455
448
456
} else {
@@ -484,7 +492,8 @@ LockedFlake lockFlake(
484
492
oldLock
485
493
? std::dynamic_pointer_cast<const Node>(oldLock)
486
494
: 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);
488
497
}
489
498
490
499
else {
@@ -504,7 +513,7 @@ LockedFlake lockFlake(
504
513
505
514
computeLocks (
506
515
flake.inputs , newLockFile.root , {},
507
- lockFlags.recreateLockFile ? nullptr : oldLockFile.root );
516
+ lockFlags.recreateLockFile ? nullptr : oldLockFile.root , false , 0 );
508
517
509
518
for (auto & i : lockFlags.inputOverrides )
510
519
if (!overridesUsed.count (i.first ))
0 commit comments