1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 09:49:36 +01:00

Add a setting to enable lazy trees

This commit is contained in:
Eelco Dolstra 2025-04-24 16:03:49 +02:00
parent 182edb4dee
commit 9d87ab1dc8
4 changed files with 14 additions and 8 deletions

View file

@ -247,6 +247,11 @@ struct EvalSettings : Config
This option can be enabled by setting `NIX_ABORT_ON_WARN=1` in the environment.
)"};
Setting<bool> lazyTrees{this, false, "lazy-trees",
R"(
If set to true, flakes and trees fetched by [`builtins.fetchTree`](@docroot@/language/builtins.md#builtins-fetchTree) are only copied to the Nix store when they're used as a dependency of a derivation. This avoids copying (potentially large) source trees unnecessarily.
)"};
};
/**

View file

@ -70,7 +70,8 @@ std::string EvalState::computeBaseName(const SourcePath & path)
StorePath EvalState::mountInput(
fetchers::Input & input, const fetchers::Input & originalInput, ref<SourceAccessor> accessor, bool requireLockable)
{
auto storePath = StorePath::random(input.getName());
auto storePath = settings.lazyTrees ? StorePath::random(input.getName())
: fetchToStore(*store, accessor, FetchMode::Copy, input.getName());
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
@ -81,11 +82,9 @@ StorePath EvalState::mountInput(
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
}
// FIXME: check NAR hash
#if 0
assert(!originalInput.getNarHash() || storePath == originalInput.computeStorePath(*store));
#endif
// FIXME: what to do with the NAR hash in lazy mode?
if (!settings.lazyTrees)
assert(!originalInput.getNarHash() || storePath == originalInput.computeStorePath(*store));
return storePath;
}