Skip to content

Commit

Permalink
Merge pull request #6662 from tweag/stiky-non-flake-overrides
Browse files Browse the repository at this point in the history
flake.cc: Make non-flake overrides sticky
  • Loading branch information
edolstra authored Jun 14, 2022
2 parents 9f58df4 + d82a3dc commit 3720a4f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ LockedFlake lockFlake(
if (!lockFlags.allowMutable && !input.ref->input.isLocked())
throw Error("cannot update flake input '%s' in pure mode", inputPathS);

/* Note: in case of an --override-input, we use
the *original* ref (input2.ref) for the
"original" field, rather than the
override. This ensures that the override isn't
nuked the next time we update the lock
file. That is, overrides are sticky unless you
use --no-write-lock-file. */
auto ref = input2.ref ? *input2.ref : *input.ref;

if (input.isFlake) {
Path localPath = parentPath;
FlakeRef localRef = *input.ref;
Expand All @@ -524,15 +533,7 @@ LockedFlake lockFlake(

auto inputFlake = getFlake(state, localRef, useRegistries, flakeCache, inputPath);

/* Note: in case of an --override-input, we use
the *original* ref (input2.ref) for the
"original" field, rather than the
override. This ensures that the override isn't
nuked the next time we update the lock
file. That is, overrides are sticky unless you
use --no-write-lock-file. */
auto childNode = std::make_shared<LockedNode>(
inputFlake.lockedRef, input2.ref ? *input2.ref : *input.ref);
auto childNode = std::make_shared<LockedNode>(inputFlake.lockedRef, ref);

node->inputs.insert_or_assign(id, childNode);

Expand Down Expand Up @@ -560,7 +561,7 @@ LockedFlake lockFlake(
auto [sourceInfo, resolvedRef, lockedRef] = fetchOrSubstituteTree(
state, *input.ref, useRegistries, flakeCache);
node->inputs.insert_or_assign(id,
std::make_shared<LockedNode>(lockedRef, *input.ref, false));
std::make_shared<LockedNode>(lockedRef, ref, false));
}
}

Expand Down

0 comments on commit 3720a4f

Please sign in to comment.