1717#include " nix/expr/print.hh"
1818#include " nix/fetchers/filtering-source-accessor.hh"
1919#include " nix/util/memory-source-accessor.hh"
20+ #include " nix/util/mounted-source-accessor.hh"
2021#include " nix/expr/gc-small-vector.hh"
2122#include " nix/util/url.hh"
2223#include " nix/fetchers/fetch-to-store.hh"
@@ -225,22 +226,25 @@ EvalState::EvalState(
225226 */
226227 {CanonPath (store->storeDir ), store->getFSAccessor (settings.pureEval )},
227228 }))
228- , rootFS(({
229- /* In pure eval mode, we provide a filesystem that only
230- contains the Nix store.
231-
232- If we have a chroot store and pure eval is not enabled,
233- use a union accessor to make the chroot store available
234- at its logical location while still having the
235- underlying directory available. This is necessary for
236- instance if we're evaluating a file from the physical
237- /nix/store while using a chroot store. */
238- auto accessor = getFSSourceAccessor ();
239-
240- auto realStoreDir = dirOf (store->toRealPath (StorePath::dummy));
241- if (settings.pureEval || store->storeDir != realStoreDir) {
242- accessor = settings.pureEval ? storeFS : makeUnionSourceAccessor ({accessor, storeFS});
243- }
229+ , rootFS([&] {
230+ auto accessor = [&]() -> decltype (rootFS) {
231+ /* In pure eval mode, we provide a filesystem that only
232+ contains the Nix store. */
233+ if (settings.pureEval )
234+ return storeFS;
235+
236+ /* If we have a chroot store and pure eval is not enabled,
237+ use a union accessor to make the chroot store available
238+ at its logical location while still having the underlying
239+ directory available. This is necessary for instance if
240+ we're evaluating a file from the physical /nix/store
241+ while using a chroot store. */
242+ auto realStoreDir = dirOf (store->toRealPath (StorePath::dummy));
243+ if (store->storeDir != realStoreDir)
244+ return makeUnionSourceAccessor ({getFSSourceAccessor (), storeFS});
245+
246+ return getFSSourceAccessor ();
247+ }();
244248
245249 /* Apply access control if needed. */
246250 if (settings.restrictEval || settings.pureEval )
@@ -251,8 +255,8 @@ EvalState::EvalState(
251255 throw RestrictedPathError (" access to absolute path '%1%' is forbidden %2%" , path, modeInformation);
252256 });
253257
254- accessor;
255- }))
258+ return accessor;
259+ }( ))
256260 , corepkgsFS(make_ref<MemorySourceAccessor>())
257261 , internalFS(make_ref<MemorySourceAccessor>())
258262 , derivationInternal{corepkgsFS->addFile (
@@ -334,7 +338,7 @@ EvalState::EvalState(
334338
335339EvalState::~EvalState () {}
336340
337- void EvalState::allowPath (const Path & path)
341+ void EvalState::allowPathLegacy (const Path & path)
338342{
339343 if (auto rootFS2 = rootFS.dynamic_pointer_cast <AllowListSourceAccessor>())
340344 rootFS2->allowPrefix (CanonPath (path));
@@ -3177,7 +3181,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
31773181
31783182 /* Allow access to paths in the search path. */
31793183 if (initAccessControl) {
3180- allowPath (path.path .abs ());
3184+ allowPathLegacy (path.path .abs ());
31813185 if (store->isInStore (path.path .abs ())) {
31823186 try {
31833187 allowClosure (store->toStorePath (path.path .abs ()).first );
0 commit comments