1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Merge pull request #12282 from DeterminateSystems/trivial-changes

Trivial changes from lazy-trees
This commit is contained in:
Eelco Dolstra 2025-01-17 00:00:07 +01:00 committed by GitHub
commit 12aff40ad7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 29 deletions

View file

@ -43,7 +43,7 @@ static std::optional<FetchedFlake> lookupInFlakeCache(
static std::tuple<StorePath, FlakeRef, FlakeRef> fetchOrSubstituteTree( static std::tuple<StorePath, FlakeRef, FlakeRef> fetchOrSubstituteTree(
EvalState & state, EvalState & state,
const FlakeRef & originalRef, const FlakeRef & originalRef,
bool allowLookup, bool useRegistries,
FlakeCache & flakeCache) FlakeCache & flakeCache)
{ {
auto fetched = lookupInFlakeCache(flakeCache, originalRef); auto fetched = lookupInFlakeCache(flakeCache, originalRef);
@ -54,7 +54,7 @@ static std::tuple<StorePath, FlakeRef, FlakeRef> fetchOrSubstituteTree(
auto [storePath, lockedRef] = originalRef.fetchTree(state.store); auto [storePath, lockedRef] = originalRef.fetchTree(state.store);
fetched.emplace(FetchedFlake{.lockedRef = lockedRef, .storePath = storePath}); fetched.emplace(FetchedFlake{.lockedRef = lockedRef, .storePath = storePath});
} else { } else {
if (allowLookup) { if (useRegistries) {
resolvedRef = originalRef.resolve( resolvedRef = originalRef.resolve(
state.store, state.store,
[](fetchers::Registry::RegistryType type) { [](fetchers::Registry::RegistryType type) {
@ -105,7 +105,7 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
EvalState & state, EvalState & state,
Value * value, Value * value,
const PosIdx pos, const PosIdx pos,
InputPath lockRootPath, const InputPath & lockRootPath,
const SourcePath & flakeDir); const SourcePath & flakeDir);
static FlakeInput parseFlakeInput( static FlakeInput parseFlakeInput(
@ -113,7 +113,7 @@ static FlakeInput parseFlakeInput(
std::string_view inputName, std::string_view inputName,
Value * value, Value * value,
const PosIdx pos, const PosIdx pos,
InputPath lockRootPath, const InputPath & lockRootPath,
const SourcePath & flakeDir) const SourcePath & flakeDir)
{ {
expectType(state, nAttrs, *value, pos); expectType(state, nAttrs, *value, pos);
@ -220,7 +220,7 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
EvalState & state, EvalState & state,
Value * value, Value * value,
const PosIdx pos, const PosIdx pos,
InputPath lockRootPath, const InputPath & lockRootPath,
const SourcePath & flakeDir) const SourcePath & flakeDir)
{ {
std::map<FlakeId, FlakeInput> inputs; std::map<FlakeId, FlakeInput> inputs;
@ -345,29 +345,23 @@ static Flake readFlake(
static Flake getFlake( static Flake getFlake(
EvalState & state, EvalState & state,
const FlakeRef & originalRef, const FlakeRef & originalRef,
bool allowLookup, bool useRegistries,
FlakeCache & flakeCache, FlakeCache & flakeCache,
InputPath lockRootPath) const InputPath & lockRootPath)
{ {
auto [storePath, resolvedRef, lockedRef] = fetchOrSubstituteTree( auto [storePath, resolvedRef, lockedRef] = fetchOrSubstituteTree(
state, originalRef, allowLookup, flakeCache); state, originalRef, useRegistries, flakeCache);
return readFlake(state, originalRef, resolvedRef, lockedRef, state.rootPath(state.store->toRealPath(storePath)), lockRootPath); return readFlake(state, originalRef, resolvedRef, lockedRef, state.rootPath(state.store->toRealPath(storePath)), lockRootPath);
} }
Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup, FlakeCache & flakeCache) Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool useRegistries)
{
return getFlake(state, originalRef, allowLookup, flakeCache, {});
}
Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup)
{ {
FlakeCache flakeCache; FlakeCache flakeCache;
return getFlake(state, originalRef, allowLookup, flakeCache); return getFlake(state, originalRef, useRegistries, flakeCache, {});
} }
static LockFile readLockFile( static LockFile readLockFile(
const Settings & settings,
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
const SourcePath & lockFilePath) const SourcePath & lockFilePath)
{ {
@ -390,7 +384,7 @@ LockedFlake lockFlake(
auto useRegistries = lockFlags.useRegistries.value_or(settings.useRegistries); auto useRegistries = lockFlags.useRegistries.value_or(settings.useRegistries);
auto flake = getFlake(state, topRef, useRegistries, flakeCache); auto flake = getFlake(state, topRef, useRegistries, flakeCache, {});
if (lockFlags.applyNixConfig) { if (lockFlags.applyNixConfig) {
flake.config.apply(settings); flake.config.apply(settings);
@ -403,7 +397,6 @@ LockedFlake lockFlake(
} }
auto oldLockFile = readLockFile( auto oldLockFile = readLockFile(
settings,
state.fetchSettings, state.fetchSettings,
lockFlags.referenceLockFilePath.value_or( lockFlags.referenceLockFilePath.value_or(
flake.lockFilePath())); flake.lockFilePath()));
@ -445,7 +438,7 @@ LockedFlake lockFlake(
ref<Node> node, ref<Node> node,
const InputPath & inputPathPrefix, const InputPath & inputPathPrefix,
std::shared_ptr<const Node> oldNode, std::shared_ptr<const Node> oldNode,
const InputPath & lockRootPath, const InputPath & followsPrefix,
const SourcePath & sourcePath, const SourcePath & sourcePath,
bool trustLock)> bool trustLock)>
computeLocks; computeLocks;
@ -461,7 +454,11 @@ LockedFlake lockFlake(
/* The old node, if any, from which locks can be /* The old node, if any, from which locks can be
copied. */ copied. */
std::shared_ptr<const Node> oldNode, std::shared_ptr<const Node> oldNode,
const InputPath & lockRootPath, /* The prefix relative to which 'follows' should be
interpreted. When a node is initially locked, it's
relative to the node's flake; when it's already locked,
it's relative to the root of the lock file. */
const InputPath & followsPrefix,
/* The source path of this node's flake. */ /* The source path of this node's flake. */
const SourcePath & sourcePath, const SourcePath & sourcePath,
bool trustLock) bool trustLock)
@ -633,7 +630,7 @@ LockedFlake lockFlake(
break; break;
} }
} }
auto absoluteFollows(lockRootPath); auto absoluteFollows(followsPrefix);
absoluteFollows.insert(absoluteFollows.end(), follows->begin(), follows->end()); absoluteFollows.insert(absoluteFollows.end(), follows->begin(), follows->end());
fakeInputs.emplace(i.first, FlakeInput { fakeInputs.emplace(i.first, FlakeInput {
.follows = absoluteFollows, .follows = absoluteFollows,
@ -645,9 +642,10 @@ LockedFlake lockFlake(
if (mustRefetch) { if (mustRefetch) {
auto inputFlake = getInputFlake(); auto inputFlake = getInputFlake();
nodePaths.emplace(childNode, inputFlake.path.parent()); nodePaths.emplace(childNode, inputFlake.path.parent());
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, lockRootPath, inputFlake.path, false); computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, followsPrefix,
inputFlake.path, false);
} else { } else {
computeLocks(fakeInputs, childNode, inputPath, oldLock, lockRootPath, sourcePath, true); computeLocks(fakeInputs, childNode, inputPath, oldLock, followsPrefix, sourcePath, true);
} }
} else { } else {
@ -672,7 +670,11 @@ LockedFlake lockFlake(
if (input.isFlake) { if (input.isFlake) {
auto inputFlake = getInputFlake(); auto inputFlake = getInputFlake();
auto childNode = make_ref<LockedNode>(inputFlake.lockedRef, ref, true, overridenParentPath); auto childNode = make_ref<LockedNode>(
inputFlake.lockedRef,
ref,
true,
overridenParentPath);
node->inputs.insert_or_assign(id, childNode); node->inputs.insert_or_assign(id, childNode);
@ -692,8 +694,8 @@ LockedFlake lockFlake(
inputFlake.inputs, childNode, inputPath, inputFlake.inputs, childNode, inputPath,
oldLock oldLock
? std::dynamic_pointer_cast<const Node>(oldLock) ? std::dynamic_pointer_cast<const Node>(oldLock)
: readLockFile(settings, state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(), : readLockFile(state.fetchSettings, inputFlake.lockFilePath()).root.get_ptr(),
oldLock ? lockRootPath : inputPath, oldLock ? followsPrefix : inputPath,
inputFlake.path, inputFlake.path,
false); false);
} }
@ -817,8 +819,7 @@ LockedFlake lockFlake(
repo, so we should re-read it. FIXME: we could repo, so we should re-read it. FIXME: we could
also just clear the 'rev' field... */ also just clear the 'rev' field... */
auto prevLockedRef = flake.lockedRef; auto prevLockedRef = flake.lockedRef;
FlakeCache dummyCache; flake = getFlake(state, topRef, useRegistries);
flake = getFlake(state, topRef, useRegistries, dummyCache);
if (lockFlags.commitLockFile && if (lockFlags.commitLockFile &&
flake.lockedRef.input.getRev() && flake.lockedRef.input.getRev() &&

View file

@ -110,7 +110,7 @@ struct Flake
} }
}; };
Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool allowLookup); Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool useRegistries);
/** /**
* Fingerprint of a locked flake; used as a cache key. * Fingerprint of a locked flake; used as a cache key.