New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix eval
doesn't understand expressions that don't begin with a paren
#3032
Comments
This is a nix ui issue so it should be in the nix repo. I'll see if someone can transfer it for you. |
Oops, thanks. I think Safari auto-completed the repo URL for me and I didn't notice. |
Also see #2078 |
This is intended behaviour. Expressions have to enclosed in parentheses, to disambiguate them from other kinds of installables (like store paths or flake references). |
The documentation for Similarly, if we can parse the argument as a flake reference, we can then treat it that way. I'm assuming a flake reference is a thing that looks like Basically what I'm getting at is |
I agree that this is confusing. I understand that disambiguate is important, but then the error message should be more explicit, and say something like "If you wanted to input a nix expression, please add parens.". The fallback is also a nice idea. |
Will close this issue since on the flakes branch (which should be merged into master soon), parentheses are no longer supported to indicate an expression. You have to use |
Describe the bug
The
nix eval
command is documented as evaluating a Nix expression, but its actual handling of the argument is rather confusing. As near as I can tell, unless the argument begins with an open paren, it's assumed to be a path identifying an attribute inNIX_PATH
. Passing anything else just emits a confusing error message saying it doesn't know what to do with the expression.To Reproduce
Steps to reproduce the behavior:
nix eval nixpkgs.hello.name
nix eval '(nixpkgs.hello.name)'
nix eval '1 + 2'
nix eval '(1 + 2)'
nix eval -f '<nixpkgs>' hello.name
nix eval -f '<nixpkgs>' '(hello.name)'
Expected behavior
nixpkgs.hello
, which for me is"hello-2.10"
undefined variable 'nixpkgs'
is acceptable.3
3
nixpkgs.hello
againActual behavior
undefined variable
warning.error: don't know what to do with argument '1 + 2'
error: undefined variable 'hello' at (string):1:2
. This one actually mystifies me; doesnix eval
just discard the-f
argument entirely if the expression begins with a paren? I would have expected it to import the attributes like it does without parens, or likenix repl
does with:l
.Additional details
In general,
nix eval
should just treat all arguments as expressions and evaluate them. The only problem with this very general approach is eithernix eval nixpkgs.hello.name
would stop working because the channels wouldn't be available as top-level attributes, or alternativelynix eval 'some-arbitrary-expression'
would be evaluated with all the channels already imported, which is probably surprising (in addition to the performance implications of always loading all entries of the path).Given that, I think reasonable behavior is
NIX_PATH
and return the results. This matches the behavior today.-f
flag was passed, load the file into the environment first, otherwise leave the environment empty.This means that
nix eval '1 + 2'
would behave just asnix eval '(1 + 2)'
does today, and it also means thatnix eval -f '<nixpkgs>' '(hello.name)'
would behave the same asnix eval -f '<nixpkgs>' hello.name
.Metadata
"x86_64-darwin"
Darwin 18.7.0, macOS 10.14.6
no
no
nix-env (Nix) 2.2.2
"nixpkgs-19.09pre186574.88d9f776091"
/Users/lily/.nix-defexpr/channels/nixpkgs
The text was updated successfully, but these errors were encountered: