Skip to content

Commit

Permalink
Fix "follows" paths in subordinate lockfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
RealityAnomaly committed Mar 17, 2021
1 parent 8127094 commit cfef23c
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,24 @@ LockedFlake lockFlake(

std::vector<FlakeRef> parents;

// isFlake = whether we are currently inside a subordinate flake
// inputDepth = inputs deep we are relative to the current root or subordinate flake
std::function<void(
const FlakeInputs & flakeInputs,
std::shared_ptr<Node> node,
const InputPath & inputPathPrefix,
std::shared_ptr<const Node> oldNode)>
std::shared_ptr<const Node> oldNode,
const bool isFlake, const int inputDepth)>
computeLocks;

computeLocks = [&](
const FlakeInputs & flakeInputs,
std::shared_ptr<Node> node,
const InputPath & inputPathPrefix,
std::shared_ptr<const Node> oldNode)
std::shared_ptr<const Node> oldNode,
const bool isFlake, const int inputDepth)
{
debug("computing lock file node '%s'", printInputPath(inputPathPrefix));
debug("computing lock file node '%s' (depth %i)", printInputPath(inputPathPrefix), inputDepth);

/* Get the overrides (i.e. attributes of the form
'inputs.nixops.inputs.nixpkgs.url = ...'). */
Expand Down Expand Up @@ -366,11 +370,21 @@ LockedFlake lockFlake(
path we haven't processed yet. */
if (input.follows) {
InputPath target;
if (hasOverride || input.absolute)
if (hasOverride || input.absolute) {
/* 'follows' from an override is relative to the
root of the graph. */
target = *input.follows;
else {
root of the graph, but we need to fix up the path for subordinate lockfiles */
if (isFlake) {
target = inputPathPrefix;

int subtract = inputDepth;
if (subtract == 0) subtract = 1;

for (int i = 0; i < subtract; i++) target.pop_back();
for (auto & i : *input.follows) target.push_back(i);
} else {
target = *input.follows;
}
} else {
/* Otherwise, it's relative to the current flake. */
target = inputPathPrefix;
for (auto & i : *input.follows) target.push_back(i);
Expand Down Expand Up @@ -420,7 +434,7 @@ LockedFlake lockFlake(
if (hasChildUpdate) {
auto inputFlake = getFlake(
state, oldLock->lockedRef, false, flakeCache);
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock);
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, isFlake, inputDepth + 1);
} else {
/* No need to fetch this flake, we can be
lazy. However there may be new overrides on the
Expand All @@ -442,7 +456,7 @@ LockedFlake lockFlake(
}
}

computeLocks(fakeInputs, childNode, inputPath, oldLock);
computeLocks(fakeInputs, childNode, inputPath, oldLock, isFlake, inputDepth + 1);
}

} else {
Expand Down Expand Up @@ -484,7 +498,9 @@ LockedFlake lockFlake(
oldLock
? std::dynamic_pointer_cast<const Node>(oldLock)
: LockFile::read(
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root);
inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock").root,
// Increment input depth if we're entering a non-lockfile flake
true, oldLock ? inputDepth + 1 : inputDepth);
}

else {
Expand All @@ -504,7 +520,7 @@ LockedFlake lockFlake(

computeLocks(
flake.inputs, newLockFile.root, {},
lockFlags.recreateLockFile ? nullptr : oldLockFile.root);
lockFlags.recreateLockFile ? nullptr : oldLockFile.root, false, 0);

for (auto & i : lockFlags.inputOverrides)
if (!overridesUsed.count(i.first))
Expand Down

0 comments on commit cfef23c

Please sign in to comment.