From e6a360a4d92eb428eeb098e7bc970d141de1618a Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 27 Apr 2021 17:24:38 +0200 Subject: primops/storePath: add trace to pure mode error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/libexpr/primops.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/libexpr/primops.cc') 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)); -- cgit v1.2.3