Skip to content

Commit 12aff40

Browse files
authored
Merge pull request #12282 from DeterminateSystems/trivial-changes
Trivial changes from lazy-trees
2 parents 17b6557 + f027109 commit 12aff40

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/libflake/flake/flake.cc

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static std::optional<FetchedFlake> lookupInFlakeCache(
4343
static std::tuple<StorePath, FlakeRef, FlakeRef> fetchOrSubstituteTree(
4444
EvalState & state,
4545
const FlakeRef & originalRef,
46-
bool allowLookup,
46+
bool useRegistries,
4747
FlakeCache & flakeCache)
4848
{
4949
auto fetched = lookupInFlakeCache(flakeCache, originalRef);
@@ -54,7 +54,7 @@ static std::tuple<StorePath, FlakeRef, FlakeRef> fetchOrSubstituteTree(
5454
auto [storePath, lockedRef] = originalRef.fetchTree(state.store);
5555
fetched.emplace(FetchedFlake{.lockedRef = lockedRef, .storePath = storePath});
5656
} else {
57-
if (allowLookup) {
57+
if (useRegistries) {
5858
resolvedRef = originalRef.resolve(
5959
state.store,
6060
[](fetchers::Registry::RegistryType type) {
@@ -105,15 +105,15 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
105105
EvalState & state,
106106
Value * value,
107107
const PosIdx pos,
108-
InputPath lockRootPath,
108+
const InputPath & lockRootPath,
109109
const SourcePath & flakeDir);
110110

111111
static FlakeInput parseFlakeInput(
112112
EvalState & state,
113113
std::string_view inputName,
114114
Value * value,
115115
const PosIdx pos,
116-
InputPath lockRootPath,
116+
const InputPath & lockRootPath,
117117
const SourcePath & flakeDir)
118118
{
119119
expectType(state, nAttrs, *value, pos);
@@ -220,7 +220,7 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
220220
EvalState & state,
221221
Value * value,
222222
const PosIdx pos,
223-
InputPath lockRootPath,
223+
const InputPath & lockRootPath,
224224
const SourcePath & flakeDir)
225225
{
226226
std::map<FlakeId, FlakeInput> inputs;
@@ -345,29 +345,23 @@ static Flake readFlake(
345345
static Flake getFlake(
346346
EvalState & state,
347347
const FlakeRef & originalRef,
348-
bool allowLookup,
348+
bool useRegistries,
349349
FlakeCache & flakeCache,
350-
InputPath lockRootPath)
350+
const InputPath & lockRootPath)
351351
{
352352
auto [storePath, resolvedRef, lockedRef] = fetchOrSubstituteTree(
353-
state, originalRef, allowLookup, flakeCache);
353+
state, originalRef, useRegistries, flakeCache);
354354

355355
return readFlake(state, originalRef, resolvedRef, lockedRef, state.rootPath(state.store->toRealPath(storePath)), lockRootPath);
356356
}
357357

358-
Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup, FlakeCache & flakeCache)
359-
{
360-
return getFlake(state, originalRef, allowLookup, flakeCache, {});
361-
}
362-
363-
Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup)
358+
Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool useRegistries)
364359
{
365360
FlakeCache flakeCache;
366-
return getFlake(state, originalRef, allowLookup, flakeCache);
361+
return getFlake(state, originalRef, useRegistries, flakeCache, {});
367362
}
368363

369364
static LockFile readLockFile(
370-
const Settings & settings,
371365
const fetchers::Settings & fetchSettings,
372366
const SourcePath & lockFilePath)
373367
{
@@ -390,7 +384,7 @@ LockedFlake lockFlake(
390384

391385
auto useRegistries = lockFlags.useRegistries.value_or(settings.useRegistries);
392386

393-
auto flake = getFlake(state, topRef, useRegistries, flakeCache);
387+
auto flake = getFlake(state, topRef, useRegistries, flakeCache, {});
394388

395389
if (lockFlags.applyNixConfig) {
396390
flake.config.apply(settings);
@@ -403,7 +397,6 @@ LockedFlake lockFlake(
403397
}
404398

405399
auto oldLockFile = readLockFile(
406-
settings,
407400
state.fetchSettings,
408401
lockFlags.referenceLockFilePath.value_or(
409402
flake.lockFilePath()));
@@ -445,7 +438,7 @@ LockedFlake lockFlake(
445438
ref<Node> node,
446439
const InputPath & inputPathPrefix,
447440
std::shared_ptr<const Node> oldNode,
448-
const InputPath & lockRootPath,
441+
const InputPath & followsPrefix,
449442
const SourcePath & sourcePath,
450443
bool trustLock)>
451444
computeLocks;
@@ -461,7 +454,11 @@ LockedFlake lockFlake(
461454
/* The old node, if any, from which locks can be
462455
copied. */
463456
std::shared_ptr<const Node> oldNode,
464-
const InputPath & lockRootPath,
457+
/* The prefix relative to which 'follows' should be
458+
interpreted. When a node is initially locked, it's
459+
relative to the node's flake; when it's already locked,
460+
it's relative to the root of the lock file. */
461+
const InputPath & followsPrefix,
465462
/* The source path of this node's flake. */
466463
const SourcePath & sourcePath,
467464
bool trustLock)
@@ -633,7 +630,7 @@ LockedFlake lockFlake(
633630
break;
634631
}
635632
}
636-
auto absoluteFollows(lockRootPath);
633+
auto absoluteFollows(followsPrefix);
637634
absoluteFollows.insert(absoluteFollows.end(), follows->begin(), follows->end());
638635
fakeInputs.emplace(i.first, FlakeInput {
639636
.follows = absoluteFollows,
@@ -645,9 +642,10 @@ LockedFlake lockFlake(
645642
if (mustRefetch) {
646643
auto inputFlake = getInputFlake();
647644
nodePaths.emplace(childNode, inputFlake.path.parent());
648-
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, lockRootPath, inputFlake.path, false);
645+
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, followsPrefix,
646+
inputFlake.path, false);
649647
} else {
650-
computeLocks(fakeInputs, childNode, inputPath, oldLock, lockRootPath, sourcePath, true);
648+
computeLocks(fakeInputs, childNode, inputPath, oldLock, followsPrefix, sourcePath, true);
651649
}
652650

653651
} else {
@@ -672,7 +670,11 @@ LockedFlake lockFlake(
672670
if (input.isFlake) {
673671
auto inputFlake = getInputFlake();
674672

675-
auto childNode = make_ref<LockedNode>(inputFlake.lockedRef, ref, true, overridenParentPath);
673+
auto childNode = make_ref<LockedNode>(
674+
inputFlake.lockedRef,
675+
ref,
676+
true,
677+
overridenParentPath);
676678

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

@@ -692,8 +694,8 @@ LockedFlake lockFlake(
692694
inputFlake.inputs, childNode, inputPath,
693695
oldLock
694696
? std::dynamic_pointer_cast<const Node>(oldLock)
695-
: readLockFile(settings, state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(),
696-
oldLock ? lockRootPath : inputPath,
697+
: readLockFile(state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(),
698+
oldLock ? followsPrefix : inputPath,
697699
inputFlake.path,
698700
false);
699701
}
@@ -817,8 +819,7 @@ LockedFlake lockFlake(
817819
repo, so we should re-read it. FIXME: we could
818820
also just clear the 'rev' field... */
819821
auto prevLockedRef = flake.lockedRef;
820-
FlakeCache dummyCache;
821-
flake = getFlake(state, topRef, useRegistries, dummyCache);
822+
flake = getFlake(state, topRef, useRegistries);
822823

823824
if (lockFlags.commitLockFile &&
824825
flake.lockedRef.input.getRev() &&

src/libflake/flake/flake.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct Flake
110110
}
111111
};
112112

113-
Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool allowLookup);
113+
Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool useRegistries);
114114

115115
/**
116116
* Fingerprint of a locked flake; used as a cache key.

0 commit comments

Comments
 (0)