1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-27 20:51:00 +01:00

Move mountInput into EvalState

This commit is contained in:
Eelco Dolstra 2025-04-23 13:52:22 +02:00
parent ff85b347b8
commit 182edb4dee
7 changed files with 48 additions and 60 deletions

View file

@ -36,6 +36,7 @@ class Store;
namespace fetchers {
struct Settings;
struct InputCache;
struct Input;
}
struct EvalSettings;
class EvalState;
@ -450,6 +451,15 @@ public:
void checkURI(const std::string & uri);
/**
* Mount an input on the Nix store.
*/
StorePath mountInput(
fetchers::Input & input,
const fetchers::Input & originalInput,
ref<SourceAccessor> accessor,
bool requireLockable);
/**
* Parse a Nix expression from the specified file.
*/

View file

@ -67,4 +67,27 @@ std::string EvalState::computeBaseName(const SourcePath & path)
return std::string(path.baseName());
}
StorePath EvalState::mountInput(
fetchers::Input & input, const fetchers::Input & originalInput, ref<SourceAccessor> accessor, bool requireLockable)
{
auto storePath = StorePath::random(input.getName());
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
if (requireLockable && !input.isLocked() && !input.getNarHash()) {
auto narHash = accessor->hashPath(CanonPath::root);
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
return storePath;
}
}

View file

@ -204,11 +204,7 @@ static void fetchTree(
auto cachedInput = state.inputCache->getAccessor(state.store, input, false);
auto storePath = StorePath::random(input.getName());
state.allowPath(storePath);
state.storeFS->mount(CanonPath(state.store->printStorePath(storePath)), cachedInput.accessor);
auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor, true);
emitTreeAttrs(state, storePath, cachedInput.lockedInput, v, params.emptyRevFallback, false);
}