nix eval is unintuitively consistent

Created on 15 Apr 2018  Â·  5Comments  Â·  Source: NixOS/nix

> cat hi.nix                                                  
4

Even though it is probably internally consistent, it is highly confusing to the user (and the error messages non-descriptive)

> nix eval --json --show-trace ./hi.nix                       
error: path '/home/philip/tmp/hi.nix' is not in the Nix store                         

Hrm, I just wanted to eval a file. Maybe I need to use -f

> nix eval --json --show-trace -f ./hi.nix                    
error: more arguments are required        

Huh, that’s strange. I gave it a file, what does it want from me? --help doesn’t exactly help, either.

> nix eval '4'                                                
error: don't know what to do with argument '4'           

What?

> nix eval '(4)'                                              
4                                                                  

wtf, seriously?

Btw, the “correct” invocation for the file is:

> nix eval -f ./hi.nix ""
4

which follows from nix(1) always requiring an argument and being consistent about it.

cc @LnL7 @grahamc

new cli

All 5 comments

Basically the same issue as #2066.
The biggeste problem with this, IMHO, is that besides being difficult to use, it's inconsistent with nix build.

FWIW, cc #1763 re:consistency problems even within nix eval itself.

So if I'm understand this correctly, the best way to evaluate some file.nix from the command line is to run:

nix eval --file ./file.nix ""

Is that right?

@wpcarro No, the best way to do it is to use nix-instantiate --eval.

The nix tool is not yet stable and its interface probably (hopefully) going to change.

On the flakes branch, you can do nix eval --file ./file.nix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewbauer picture matthewbauer  Â·  3Comments

bennofs picture bennofs  Â·  3Comments

vaibhavsagar picture vaibhavsagar  Â·  3Comments

ericsagnes picture ericsagnes  Â·  3Comments

dasJ picture dasJ  Â·  3Comments