From 43a26916c25fff151698a1721793e0097251d07b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 18 Apr 2025 16:01:19 +0200 Subject: [PATCH] unsafeGetAttrPos: Set string context on store paths This is needed to devirtualize them when they get passed to a derivation or builtins.toFile. Arguably, since this builtin is unsafe, we could just ignore this, but we may as well do the correct thing. --- src/libexpr/eval.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 12b11f1ac..b898d8ef5 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -948,7 +948,16 @@ void EvalState::mkPos(Value & v, PosIdx p) auto origin = positions.originOf(p); if (auto path = std::get_if(&origin)) { auto attrs = buildBindings(3); - attrs.alloc(sFile).mkString(path->path.abs()); + if (path->accessor == rootFS && store->isInStore(path->path.abs())) + // FIXME: only do this for virtual store paths? + attrs.alloc(sFile).mkString(path->path.abs(), + { + NixStringContextElem::Opaque{ + .path = store->toStorePath(path->path.abs()).first + } + }); + else + attrs.alloc(sFile).mkString(path->path.abs()); makePositionThunks(*this, p, attrs.alloc(sLine), attrs.alloc(sColumn)); v.mkAttrs(attrs); } else