2020#include " nix/util/url.hh"
2121#include " nix/fetchers/fetch-to-store.hh"
2222#include " nix/fetchers/tarball.hh"
23+ #include " nix/fetchers/input-cache.hh"
2324
2425#include " parser-tab.hh"
2526
@@ -266,12 +267,9 @@ EvalState::EvalState(
266267 /nix/store while using a chroot store. */
267268 auto accessor = getFSSourceAccessor ();
268269
269- auto realStoreDir = dirOf (store->toRealPath (StorePath::dummy));
270- if (settings.pureEval || store->storeDir != realStoreDir) {
271- accessor = settings.pureEval
272- ? storeFS.cast <SourceAccessor>()
273- : makeUnionSourceAccessor ({accessor, storeFS});
274- }
270+ accessor = settings.pureEval
271+ ? storeFS.cast <SourceAccessor>()
272+ : makeUnionSourceAccessor ({accessor, storeFS});
275273
276274 /* Apply access control if needed. */
277275 if (settings.restrictEval || settings.pureEval )
@@ -293,6 +291,7 @@ EvalState::EvalState(
293291 )}
294292 , store(store)
295293 , buildStore(buildStore ? buildStore : store)
294+ , inputCache(fetchers::InputCache::create())
296295 , debugRepl(nullptr )
297296 , debugStop(false )
298297 , trylevel(0 )
@@ -949,7 +948,16 @@ void EvalState::mkPos(Value & v, PosIdx p)
949948 auto origin = positions.originOf (p);
950949 if (auto path = std::get_if<SourcePath>(&origin)) {
951950 auto attrs = buildBindings (3 );
952- attrs.alloc (sFile ).mkString (path->path .abs ());
951+ if (path->accessor == rootFS && store->isInStore (path->path .abs ()))
952+ // FIXME: only do this for virtual store paths?
953+ attrs.alloc (sFile ).mkString (path->path .abs (),
954+ {
955+ NixStringContextElem::Opaque{
956+ .path = store->toStorePath (path->path .abs ()).first
957+ }
958+ });
959+ else
960+ attrs.alloc (sFile ).mkString (path->path .abs ());
953961 makePositionThunks (*this , p, attrs.alloc (sLine ), attrs.alloc (sColumn ));
954962 v.mkAttrs (attrs);
955963 } else
@@ -1135,6 +1143,7 @@ void EvalState::resetFileCache()
11351143{
11361144 fileEvalCache.clear ();
11371145 fileParseCache.clear ();
1146+ inputCache->clear ();
11381147}
11391148
11401149
@@ -2317,6 +2326,9 @@ BackedStringView EvalState::coerceToString(
23172326 }
23182327
23192328 if (v.type () == nPath) {
2329+ // FIXME: instead of copying the path to the store, we could
2330+ // return a virtual store path that lazily copies the path to
2331+ // the store in devirtualize().
23202332 return
23212333 !canonicalizePath && !copyToStore
23222334 ? // FIXME: hack to preserve path literals that end in a
@@ -2406,7 +2418,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
24062418 *store,
24072419 path.resolveSymlinks (SymlinkResolution::Ancestors),
24082420 settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
2409- path. baseName ( ),
2421+ computeBaseName (path ),
24102422 ContentAddressMethod::Raw::NixArchive,
24112423 nullptr ,
24122424 repair);
@@ -2461,7 +2473,7 @@ StorePath EvalState::coerceToStorePath(const PosIdx pos, Value & v, NixStringCon
24612473 auto path = coerceToString (pos, v, context, errorCtx, false , false , true ).toOwned ();
24622474 if (auto storePath = store->maybeParseStorePath (path))
24632475 return *storePath;
2464- error<EvalError>(" path '%1%' is not in the Nix store" , path).withTrace (pos, errorCtx).debugThrow ();
2476+ error<EvalError>(" cannot coerce '%s' to a store path because it is not a subpath of the Nix store" , path).withTrace (pos, errorCtx).debugThrow ();
24652477}
24662478
24672479
0 commit comments