Nix eval has terrible messages; how to improve?

I’m curious to better understand why my nix eval usage is producing poor messages (my point of view).

❯ nix eval nixpkgs.hello.out
error: anonymous function at /nix/store/gdflb67a61c01i8pd9dpqxvvjag5m345-nixpkgs-21.11pre295670.189a1368878/nixpkgs/pkgs/build-support/fetchurl/boot.nix:5:1 called with unexpected argument 'meta', at /nix/store/gdflb67a61c01i8pd9dpqxvvjag5m345-nixpkgs-21.11pre295670.189a1368878/nixpkgs/pkgs/build-support/fetchzip/default.nix:18:2
(use '--show-trace' to show detailed location information)

If I try to do the same thing in nix repl seems to work fine.

❯ nix repl
Welcome to Nix version 2.3.12. Type :? for help.

nix-repl> :l <nixpkgs>
Added 14373 variables.

nix-repl> hello.out
«derivation /nix/store/wqnx5cgcabxkfp771fmjr1nw7mjr9zlm-hello-2.10.drv»

I’m running into a few weird things when trying nix eval if I try to eval anything but a simple type.

2 Likes

For what it’s worth, nix 2.4’s error messages will be a little better. even though in this case it’s not really helpful at all.

$ nix eval nixpkgs#hello
error: anonymous function at /nix/store/h7b0frzjk6ylyqq471m667yd9bl9n6fm-source/pkgs/build-support/fetchurl/boot.nix:5:1 called with unexpected argument 'meta'

       at /nix/store/h7b0frzjk6ylyqq471m667yd9bl9n6fm-source/pkgs/build-support/fetchzip/default.nix:18:2:

           17|
           18| (fetchurl (let
             |  ^
           19|   basename = baseNameOf (if url != "" then url else builtins.head urls);
(use '--show-trace' to show detailed location information)

I’m not sure what you’re trying to achieve or what nix eval is generally used for, but it doesn’t seem to like returning attrsets, the following did work:

$ nix eval nixpkgs#hello.out --apply builtins.toString
"/nix/store/v6q5l9mj049v6dd8n986fndak4m898g0-hello-2.10"
$ nix eval nixpkgs#hello.out.outPath
"/nix/store/v6q5l9mj049v6dd8n986fndak4m898g0-hello-2.10"
$ nix eval nixpkgs#hello.out --raw
/nix/store/v6q5l9mj049v6dd8n986fndak4m898g0-hello-2.10

I can return basic attrSets with nix eval like niv eval '{}' so I think it’s something else.

Was really enjoying introspection of eval and trying to understand it better.

The difference between it and REPL are confusing.

Derivations from nixpkgs are really complicated attrsets that reference all sorts of stuff, some of which error out. nix repl has special cases that handle type = "derivation" and stop early by printing a short string, but nix eval doesn’t know to do so.

I can’t remember where it is, but IIRC there’s an issue on GitHub about this.