`nix-instantiate --eval` output is ambiguous
Describe the bug
nix-instantiate --eval output is ambiguous and can be misleading. nix-instantiate uses angle brackets like <CODE> to represent placeholders; this is ambiguous because <CODE> is valid Nix path syntax.
This results in the unintuitive result that nix-instantiate --parse and nix-instantiate --eval do not mirror each other or compose together. This also makes nix-instantiate --eval output unsuitable for machine consumption.
Steps To Reproduce
$ nix-instantiate --eval --expr '{ a = {}; }'
{ a = <CODE>; }
$ nix-instantiate --eval --expr '{ a = <CODE>; }'
{ a = <CODE>; }
Expected behavior
Placeholders in nix-instantiate output should not be valid/parsable Nix expressions.
If nix-instantiate's output used chevrons in the style of nix repl (e.g., «code» instead of <CODE>), then attempting to parse them as Nix expressions would fail instead of producing an unrelated expression. @edolstra cited this reasoning when changing <REPEAT> to «repeated» in nix-instantiate output in https://github.com/NixOS/nix/commit/732296ddc078f9cce8ffeb3131fef8898330b6ae.
nix-env --version output
nix-env (Nix) 2.18.1
Additional context
#8671, #8672, #9606, "Is <CODE> in nix-instantiate part of the stable API?" on NixOS discourse
Priorities
Add :+1: to issues you find important.
While it is not particularly elegant, the output is not ambiguous. There is no way to make nix-instantiate --eval (using --strict or not) to print <CODE> except if the value shown is a thunk: nix-instantiate -E '{ x = <nixpkgs>; }' will produce { x = <CODE>; } as an output just the same as feeding that output into nix-instantiate again. The result of a forced <…> expression would be printed as a path and never as a string in angle brackets. (<CODE> would then fail given most people's NIX_PATH).
Discussed during the Nix maintenance team meeting on 2024-01-12. We'll keep this open for reference, but probably don't want to act on this
- @edolstra
nix-instantiate --evalwas never meant to generate a valid Nix expression any way
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2021-01-11-nix-team-meeting-minutes-115/38277/1
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/whats-nixs-stable-api-is-code-in-nix-instantiate-part-of-it/37986/5
:+1: on changing <CODE> to «code».
Coincidentally, is there a way to eagerly print blocks that would otherwise be <CODE> with nix-instantiate?