@@ -35,8 +35,16 @@ namespace nix::flake::primops {
3535PrimOp getFlake (const Settings & settings)
3636{
3737 auto prim_getFlake = [&settings](EvalState & state, const PosIdx pos, Value ** args, Value & v) {
38+ NixStringContext context;
3839 std::string flakeRefS (
39- state.forceStringNoCtx (*args[0 ], pos, " while evaluating the argument passed to builtins.getFlake" ));
40+ state.forceString (*args[0 ], context, pos, " while evaluating the argument passed to builtins.getFlake" ));
41+ auto rewrites = state.realiseContext (context);
42+ flakeRefS = state.devirtualize (rewriteStrings (flakeRefS, rewrites), context);
43+ if (hasContext (context))
44+ // FIXME: this should really be an error.
45+ warn (
46+ " In 'builtins.getFlake', the flakeref '%s' has string context, but that's not allowed. This may become a fatal error in the future." ,
47+ flakeRefS);
4048 auto flakeRef = nix::parseFlakeRef (state.fetchSettings , flakeRefS, {}, true );
4149 if (state.settings .pureEval && !flakeRef.input .isLocked (state.fetchSettings ))
4250 throw Error (
@@ -125,7 +133,9 @@ static void prim_flakeRefToString(EvalState & state, const PosIdx pos, Value **
125133{
126134 state.forceAttrs (*args[0 ], noPos, " while evaluating the argument passed to builtins.flakeRefToString" );
127135 fetchers::Attrs attrs;
136+ NixStringContext context;
128137 for (const auto & attr : *args[0 ]->attrs ()) {
138+ state.forceValue (*attr.value , attr.pos );
129139 auto t = attr.value ->type ();
130140 if (t == nInt) {
131141 auto intValue = attr.value ->integer ().value ;
@@ -142,7 +152,9 @@ static void prim_flakeRefToString(EvalState & state, const PosIdx pos, Value **
142152 } else if (t == nBool) {
143153 attrs.emplace (state.symbols [attr.name ], Explicit<bool >{attr.value ->boolean ()});
144154 } else if (t == nString) {
145- attrs.emplace (state.symbols [attr.name ], std::string (attr.value ->string_view ()));
155+ auto s = state.forceString (
156+ *attr.value , context, attr.pos , " while evaluating an attribute in 'builtins.flakeRefToString'" );
157+ attrs.emplace (state.symbols [attr.name ], std::string (s));
146158 } else {
147159 state
148160 .error <EvalError>(
@@ -154,7 +166,7 @@ static void prim_flakeRefToString(EvalState & state, const PosIdx pos, Value **
154166 }
155167 }
156168 auto flakeRef = FlakeRef::fromAttrs (state.fetchSettings , attrs);
157- v.mkString (flakeRef.to_string (), state.mem );
169+ v.mkString (flakeRef.to_string (), context, state.mem );
158170}
159171
160172nix::PrimOp flakeRefToString ({
0 commit comments