Open msteen opened 5 years ago
The issue still persists. Another workaround is:
mystr="content" nix eval 'import ./dostuff.nix (getenv "mystr")'
I ran into this same issue today on the latest nix preview. Seems it's still broken. The workaround is still valid, however the command is a little different:
mystr="content" nix eval --impure --expr 'import ./dostuff.nix (getenv "mystr")'
I marked this as stale due to inactivity. → More info
Still important. Also run into this issue.
I marked this as stale due to inactivity. → More info
The issue remains in Nix 2.4
I would really love to have a solution here. I especially want --argstr
support so I can pass arbitrary strings into expressions without having to worry about escaping them properly.
the issue is still present in 2.9.1
Also ran into this issue.
@edolstra is this intentional or is this a bug? If the former we should update nix eval
‘s documentation (I’d be happy to submit a PR).
Bump
If I were going to fix this to essentially auto call files which are functions and pass args exactly like nix build
, would that be something that could merge? ( assuming it was implemented in a sane manner )
@edolstra
Discussed in Today's Nix team meeting:
--arg
and--apply
can be unified with something discussed previously
nix build --apply '{ hello, foo }: ...' hello=nixpkgs#hello foo=nixpkgs#firefox
nix build --apply '{ f, hello}: f hello' hello=nixpkgs#hello f=myFlake#myFun
- perhaps
nix build --expr 'f hello' --let f=nixpkgs#bundle hello=nixpkgs#hello
- overrideInputs and impure
- how much of the language do we want to reimplement as CLI flags? (and how)
- @infinisil's pure eval proposal may affect the design
nix eval --expr ... --arg ...
is already quite similar to--apply
proposals aboveThis depends on too much unsettled stuff, let's postpone it until we have more information to inform the design.
As a stop-gap, can make
--arg
/--argstr
without attribute selection an error rather than silently ignored.
The gist of it is that we don't yet know what we want, and we don't think we'll be able to figure out very soon / other stuff on the CLI stabilization hot-path comes first (we can leave these flags experimental even if the base nix eval
is stable).
The stop gap however at least will make it less surprising --- rather than the flags silently being ignored, it will be an error that they are used.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2024-01-08-nix-team-meeting-minutes-114/38156/1
Another workaround using --apply
:
nix eval --expr '({ foo }: foo)' --apply 'f: f { foo = true; }'
According to
nix eval --help
, it has support for--arg
and--argstr
:I assume it works like it does for
nix-instantiate
and others, but when I try to use it, they seem to be ignored:I also tried supplying a file to see if it was only not working for expressions, but alas:
While the same expression with
nix-instantiate
does work as expected:Am I misunderstanding something, or is this a bug?
For now I work around it by injecting the string literal directly into my expression by first escaping it: