-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support limiting attributes and list items in value printing to support detailed errors #9606
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,13 +35,50 @@ standard input. | |
|
|
||
| - `--parse`\ | ||
| Just parse the input files, and print their abstract syntax trees on | ||
| standard output in ATerm format. | ||
| standard output as a Nix expression. | ||
|
|
||
| - `--eval`\ | ||
| Just parse and evaluate the input files, and print the resulting | ||
| values on standard output. No instantiation of store derivations | ||
| takes place. | ||
|
|
||
| > **Warning** | ||
| > | ||
| > This option produces ambiguous output which is not suitable for machine | ||
| > consumption. For example, these two Nix expressions print the same result | ||
| > despite having different types: | ||
| > | ||
| > ```console | ||
| > $ nix-instantiate --eval --expr '{ a = {}; }' | ||
| > { a = <CODE>; } | ||
| > $ nix-instantiate --eval --expr '{ a = <CODE>; }' | ||
| > { a = <CODE>; } | ||
| > ``` | ||
| > | ||
| > For human-readable output, `nix eval` (experimental) is more informative: | ||
| > | ||
| > ```console | ||
| > $ nix-instantiate --eval --expr 'a: a' | ||
| > <LAMBDA> | ||
| > $ nix eval --expr 'a: a' | ||
| > «lambda @ «string»:1:1» | ||
| > ``` | ||
| > | ||
| > For machine-readable output, the `--xml` option produces unambiguous | ||
| > output: | ||
| > | ||
| > ```console | ||
| > $ nix-instantiate --eval --xml --expr '{ foo = <CODE>; }' | ||
| > <?xml version='1.0' encoding='utf-8'?> | ||
| > <expr> | ||
| > <attrs> | ||
| > <attr column="3" line="1" name="foo"> | ||
| > <unevaluated /> | ||
| > </attr> | ||
| > </attrs> | ||
| > </expr> | ||
| > ``` | ||
|
|
||
| - `--find-file`\ | ||
| Look up the given files in Nix’s search path (as specified by the | ||
| `NIX_PATH` environment variable). If found, print the corresponding | ||
|
|
@@ -61,11 +98,11 @@ standard input. | |
|
|
||
| - `--json`\ | ||
| When used with `--eval`, print the resulting value as an JSON | ||
| representation of the abstract syntax tree rather than as an ATerm. | ||
| representation of the abstract syntax tree rather than as a Nix expression. | ||
|
|
||
| - `--xml`\ | ||
| When used with `--eval`, print the resulting value as an XML | ||
| representation of the abstract syntax tree rather than as an ATerm. | ||
| representation of the abstract syntax tree rather than as a Nix expression. | ||
| The schema is the same as that used by the [`toXML` | ||
| built-in](../language/builtins.md). | ||
|
|
||
|
|
@@ -133,28 +170,29 @@ $ nix-instantiate --eval --xml --expr '1 + 2' | |
| The difference between non-strict and strict evaluation: | ||
|
|
||
| ```console | ||
| $ nix-instantiate --eval --xml --expr 'rec { x = "foo"; y = x; }' | ||
| ... | ||
| <attr name="x"> | ||
| <string value="foo" /> | ||
| </attr> | ||
| <attr name="y"> | ||
| <unevaluated /> | ||
| </attr> | ||
| ... | ||
| $ nix-instantiate --eval --xml --expr '{ x = {}; }' | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <expr> | ||
| <attrs> | ||
| <attr column="3" line="1" name="x"> | ||
| <unevaluated /> | ||
| </attr> | ||
| </attrs> | ||
| </expr> | ||
| ``` | ||
|
|
||
| Note that `y` is left unevaluated (the XML representation doesn’t | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #9755. |
||
| attempt to show non-normal forms). | ||
|
|
||
| ```console | ||
| $ nix-instantiate --eval --xml --strict --expr 'rec { x = "foo"; y = x; }' | ||
| ... | ||
| <attr name="x"> | ||
| <string value="foo" /> | ||
| </attr> | ||
| <attr name="y"> | ||
| <string value="foo" /> | ||
| </attr> | ||
| ... | ||
| $ nix-instantiate --eval --xml --strict --expr '{ x = {}; }' | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <expr> | ||
| <attrs> | ||
| <attr column="3" line="1" name="x"> | ||
| <attrs> | ||
| </attrs> | ||
| </attr> | ||
| </attrs> | ||
| </expr> | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably they have the same type at this time,
tThunk, maybe “despite not being equal” would be better? In any case, this is sort of the point of not forcing the value completely,nix evalwill also print the same output for non-equal values/values where the type isn't the same.Wouldn't be clearer to just say that the problem with the output is that it produces something that can be parsed as a Nix expression, but would not return the same result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree and actually it is ambiguous what the ambiguity is. It can be either
--strictwasn't specified,rant: why lawyering about "non-value expression"
I don't think we should ever conflate values and their expression literal counterparts, but someone might take that view and I had to be explicit. "expression" should have been enough IMO. The thing represented by
Expr.We really need to define some language terminology in the manual, but I do feel that we should just improve this text first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #9755.