lix/src/libexpr
Maximilian Bosch e6a360a4d9
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
2021-04-27 17:24:38 +02:00
..
flake Fix some typos 2021-03-26 16:14:38 +01:00
primops Add FIXME 2021-01-25 14:43:16 +01:00
attr-path.cc string2Int(): Return std::optional 2021-01-08 12:22:21 +01:00
attr-path.hh Some backports from the flakes branch 2020-06-18 14:03:00 +02:00
attr-set.cc Replace Value type setters with mk* functions 2020-12-18 21:48:22 +01:00
attr-set.hh Improve error formatting 2021-01-21 11:02:09 +01:00
common-eval-args.cc Group common options 2021-01-25 19:03:13 +01:00
common-eval-args.hh Fix --override-flake and add a test 2020-01-22 20:00:58 +01:00
eval-cache.cc libcmd/installables: force re-evaluation of cached failures 2021-04-19 19:51:04 +02:00
eval-cache.hh libcmd/installables: force re-evaluation of cached failures 2021-04-19 19:51:04 +02:00
eval-inline.hh Improve error formatting 2021-01-21 11:02:09 +01:00
eval.cc EvalSettings::getDefaultNixPath: respect {restrict,pure}Eval 2021-04-12 12:37:15 -04:00
eval.hh Move <nix/fetchurl.nix> into the nix binary 2020-12-22 14:43:20 +01:00
fetchurl.nix Move <nix/fetchurl.nix> into the nix binary 2020-12-22 14:43:20 +01:00
function-trace.cc Revert the enum struct change 2020-06-18 22:11:26 +00:00
function-trace.hh Hide FunctionCallTrace constructor/destructor 2020-01-05 16:21:34 +01:00
get-drvs.cc Use BuildableReq for buildPaths and ensurePath 2021-04-05 08:33:00 -04:00
get-drvs.hh Squashed get CA derivations building 2020-08-07 19:51:55 +00:00
imported-drv-to-derivation.nix Move some corepkgs into the nix binary 2020-03-11 16:57:48 +01:00
json-to-value.cc Bump nlohmann-json version to 3.9.1 2020-09-21 14:24:43 -04:00
json-to-value.hh Fix extra ; warnings involving MakeError 2019-11-10 11:24:47 -05:00
lexer.l Remove an unknown pragma gcc warning 2020-12-02 14:33:20 +01:00
local.mk Move <nix/fetchurl.nix> into the nix binary 2020-12-22 14:43:20 +01:00
nix-expr.pc.in pkg-config files: Use c++17 2019-03-14 14:11:12 +01:00
nixexpr.cc Improve error formatting 2021-01-21 11:02:09 +01:00
nixexpr.hh Make missing auto-call arguments throw an eval error 2021-02-22 16:13:09 +01:00
parser.y Improve error formatting 2021-01-21 11:02:09 +01:00
primops.cc primops/storePath: add trace to pure mode error 2021-04-27 17:24:38 +02:00
primops.hh Add missing #pragma once 2020-10-06 10:40:07 +02:00
symbol-table.hh nix flake show: Use evaluation cache 2020-04-17 01:02:29 +02:00
value-to-json.cc Rename Value::normalType() -> Value::type() 2020-12-17 14:45:45 +01:00
value-to-json.hh nix path-info: Add --json flag 2016-08-29 17:29:24 +02:00
value-to-xml.cc Rename Value::normalType() -> Value::type() 2020-12-17 14:45:45 +01:00
value-to-xml.hh Use "#pragma once" to prevent repeated header file inclusion 2012-07-18 14:59:03 -04:00
value.hh Replace Value type setters with mk* functions 2020-12-18 21:48:22 +01:00