1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 03:09:35 +01:00

Mount flake input source accessors on top of storeFS

This way, we don't need the PathDisplaySourceAccessor source accessor
hack, since error messages are produced directly by the original
source accessor.

In fact, we don't even need to copy the inputs to the store at all, so
this gets us very close to lazy trees. We just need to know the store
path so that requires hashing the entire input, which isn't lazy. But
the next step will be to use a virtual store path that gets rewritten
to the actual store path only when needed.
This commit is contained in:
Eelco Dolstra 2025-04-01 17:29:15 +02:00
parent fcddf4afe3
commit 73b1754816
14 changed files with 66 additions and 117 deletions

View file

@ -14,8 +14,8 @@
#include "profiles.hh"
#include "print.hh"
#include "filtering-source-accessor.hh"
#include "forwarding-source-accessor.hh"
#include "memory-source-accessor.hh"
#include "mounted-source-accessor.hh"
#include "gc-small-vector.hh"
#include "url.hh"
#include "fetch-to-store.hh"
@ -181,34 +181,6 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
}
}
struct PathDisplaySourceAccessor : ForwardingSourceAccessor
{
ref<EvalState::StorePathAccessors> storePathAccessors;
PathDisplaySourceAccessor(
ref<SourceAccessor> next,
ref<EvalState::StorePathAccessors> storePathAccessors)
: ForwardingSourceAccessor(next)
, storePathAccessors(storePathAccessors)
{
}
std::string showPath(const CanonPath & path) override
{
/* Find the accessor that produced `path`, if any, and use it
to render a more informative path
(e.g. `«github:foo/bar»/flake.nix` rather than
`/nix/store/hash.../flake.nix`). */
auto ub = storePathAccessors->upper_bound(path);
if (ub != storePathAccessors->begin())
ub--;
if (ub != storePathAccessors->end() && path.isWithin(ub->first))
return ub->second->showPath(path.removePrefix(ub->first));
else
return next->showPath(path);
}
};
static constexpr size_t BASE_ENV_SIZE = 128;
EvalState::EvalState(
@ -274,7 +246,12 @@ EvalState::EvalState(
}
, repair(NoRepair)
, emptyBindings(0)
, storePathAccessors(make_ref<StorePathAccessors>())
, storeFS(
makeMountedSourceAccessor(
{
{CanonPath::root, makeEmptySourceAccessor()},
{CanonPath(store->storeDir), makeFSSourceAccessor(dirOf(store->toRealPath(StorePath::dummy)))}
}))
, rootFS(
({
/* In pure eval mode, we provide a filesystem that only
@ -290,18 +267,11 @@ EvalState::EvalState(
auto realStoreDir = dirOf(store->toRealPath(StorePath::dummy));
if (settings.pureEval || store->storeDir != realStoreDir) {
auto storeFS = makeMountedSourceAccessor(
{
{CanonPath::root, makeEmptySourceAccessor()},
{CanonPath(store->storeDir), makeFSSourceAccessor(realStoreDir)}
});
accessor = settings.pureEval
? storeFS
? storeFS.cast<SourceAccessor>()
: makeUnionSourceAccessor({accessor, storeFS});
}
accessor = make_ref<PathDisplaySourceAccessor>(accessor, storePathAccessors);
/* Apply access control if needed. */
if (settings.restrictEval || settings.pureEval)
accessor = AllowListSourceAccessor::create(accessor, {}, {},

View file

@ -37,6 +37,7 @@ class StorePath;
struct SingleDerivedPath;
enum RepairFlag : bool;
struct MemorySourceAccessor;
struct MountedSourceAccessor;
namespace eval_cache {
class EvalCache;
}
@ -262,15 +263,10 @@ public:
/** `"unknown"` */
Value vStringUnknown;
using StorePathAccessors = std::map<CanonPath, ref<SourceAccessor>>;
/**
* A map back to the original `SourceAccessor`s used to produce
* store paths. We keep track of this to produce error messages
* that refer to the original flakerefs.
* FIXME: use Sync.
* The accessor corresponding to `store`.
*/
ref<StorePathAccessors> storePathAccessors;
const ref<MountedSourceAccessor> storeFS;
/**
* The accessor for the root filesystem.

View file

@ -10,6 +10,7 @@
#include "url.hh"
#include "value-to-json.hh"
#include "fetch-to-store.hh"
#include "mounted-source-accessor.hh"
#include <nlohmann/json.hpp>
@ -204,7 +205,7 @@ static void fetchTree(
state.allowPath(storePath);
state.storePathAccessors->insert_or_assign(CanonPath(state.store->printStorePath(storePath)), accessor);
state.storeFS->mount(CanonPath(state.store->printStorePath(storePath)), accessor);
emitTreeAttrs(state, storePath, input2, v, params.emptyRevFallback, false);
}