@@ -35,36 +35,39 @@ 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;
39- std::string flakeRefS (
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);
48- auto flakeRef = nix::parseFlakeRef (state.fetchSettings , flakeRefS, {}, true );
49- if (state.settings .pureEval && !flakeRef.input .isLocked (state.fetchSettings ))
50- throw Error (
51- " cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)" ,
52- flakeRefS,
53- state.positions [pos]);
54-
55- callFlake (
56- state,
57- lockFlake (
58- settings,
59- state,
60- flakeRef,
61- LockFlags{
62- .updateLockFile = false ,
63- .writeLockFile = false ,
64- .useRegistries = !state.settings .pureEval && settings.useRegistries ,
65- .allowUnlocked = !state.settings .pureEval ,
66- }),
67- v);
38+ state.forceValue (*args[0 ], pos);
39+
40+ LockFlags lockFlags{
41+ .updateLockFile = false ,
42+ .writeLockFile = false ,
43+ .useRegistries = !state.settings .pureEval && settings.useRegistries ,
44+ .allowUnlocked = !state.settings .pureEval ,
45+ };
46+
47+ if (args[0 ]->type () == nPath) {
48+ auto path = state.realisePath (pos, *args[0 ]);
49+ callFlake (state, lockFlake (settings, state, path, lockFlags), v);
50+ } else {
51+ NixStringContext context;
52+ std::string flakeRefS (
53+ state.forceString (*args[0 ], context, pos, " while evaluating the argument passed to builtins.getFlake" ));
54+ auto rewrites = state.realiseContext (context);
55+ flakeRefS = state.devirtualize (rewriteStrings (flakeRefS, rewrites), context);
56+ if (hasContext (context))
57+ // FIXME: this should really be an error.
58+ warn (
59+ " In 'builtins.getFlake', the flakeref '%s' has string context, but that's not allowed. This may become a fatal error in the future." ,
60+ flakeRefS);
61+
62+ auto flakeRef = nix::parseFlakeRef (state.fetchSettings , flakeRefS, {}, true );
63+ if (state.settings .pureEval && !flakeRef.input .isLocked (state.fetchSettings ))
64+ throw Error (
65+ " cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)" ,
66+ flakeRefS,
67+ state.positions [pos]);
68+
69+ callFlake (state, lockFlake (settings, state, flakeRef, lockFlags), v);
70+ }
6871 };
6972
7073 return PrimOp{
0 commit comments