When evaluating Nix expressions, the expression evaluator will automatically try to call functions that it encounters. It can automatically call functions for which every argument has a default value (e.g., { argName ? defaultValue }: ...).
But when I try to evaluate my test expression from a file:
> nix-instantiate --eval -E '{ x ? "xxx" }: { y = x; }'
<LAMBDA>
I understand that the behavior is a bit confusing, but it kind of makes sense too. When you evaluate a function, you get a <lambda>, which is exactly the same.
Passing an argument, you explicitly state that you expect a function, and that function to be called with your arg. The same can be mimicked in the expression itself:
$ nix-instantiate --eval -E '({ x ? "xxx" }: { y = x; }) {}'
{ y = "xxx"; }
What confuses me is why the --strict does not work on that lambda. Possibly something to be patched.
As far as I understand, the following should work, but does not. Feels like a bug in either the code or the doc:
$ nix-instantiate --eval --strict -E '{ x ? "xxx" }: { y = x; }'
I agree that the --strict flag here is the issue. If I was not using it’d expect to get back <LAMBDA>, but because I am specifying --strict I’d expect it to evaluate the function:
Although the manual does not say it should evaluate functions:
When used with --eval, recursively evaluate list elements and attributes. Normally, such sub-expressions are left unevaluated (since the Nix expression language is lazy).
But it would be a more intuitive behavior. Thanks for explaining.