aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2021-04-27 17:24:38 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2021-04-27 17:24:38 +0200
commite6a360a4d92eb428eeb098e7bc970d141de1618a (patch)
tree4a7cfb6639f9a8cabc42aebe983f506eb84904fe /src/libexpr/primops.cc
parent3cbad4b035939b99683265118d4f01c4b21a7a19 (diff)
primops/storePath: add trace to pure mode error
As described in #4745 it's otherwise fairly hard to understand where this is coming from. Say you have an expression which uses e.g. `types.package`: ``` nix { outputs = { self, nixpkgs }: { packages.x86_64-linux.hello = let foo = nixpkgs.lib.evalModules { modules = [ { options.foo.bar = with nixpkgs.lib; mkOption { type = types.package; }; } { foo.bar = ./.; } ]; }; in builtins.trace foo.config.foo.bar.outPath nixpkgs.legacyPackages.x86_64-linux.hello; defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; }; } ``` Then you'll get an error trace like this: ``` error: 'builtins.storePath' is not allowed in pure evaluation mode at /nix/store/p4h2x6r80njkb0j2rc1xjhhl99yri3zb-source/lib/attrsets.nix:328:15: 327| let 328| path' = builtins.storePath path; | ^ 329| res = … while evaluating the attribute 'config.foo.bar.outPath' at /nix/store/p4h2x6r80njkb0j2rc1xjhhl99yri3zb-source/lib/attrsets.nix:332:11: 331| name = sanitizeDerivationName (builtins.substring 33 (-1) (baseNameOf path')); 332| outPath = path'; | ^ 333| outputs = [ "out" ]; … while evaluating the attribute 'packages.x86_64-linux.hello' at /nix/store/6c1rfsqzrhjw1235palzjmf5vihcpci7-source/flake.nix:3:5: 2| { outputs = { self, nixpkgs }: { 3| packages.x86_64-linux.hello = let | ^ 4| foo = nixpkgs.lib.evalModules { ``` Fixes #4745
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 428adf4c2..1b9948eaf 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1210,7 +1210,10 @@ static RegisterPrimOp primop_toPath({
static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
if (evalSettings.pureEval)
- throw EvalError("builtins.storePath' is not allowed in pure evaluation mode");
+ throw EvalError({
+ .msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
+ .errPos = pos
+ });
PathSet context;
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));