-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a JSON Schema for Derivation
#14269
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
Conversation
7c58407 to
6839d7f
Compare
Derivation
1475a77 to
f5e6a86
Compare
|
OK this now goes to |
f5e6a86 to
3a851a7
Compare
For manual, and testing formats
3a851a7 to
01b001d
Compare
|
@roberth if you informally approve the parts that I did, I am happy with the parts that you did, and then we can merge it. Note that I changed it around so that the tests data's canonical location is back in the |
| # # Not sure how to make subschema work | ||
| # { | ||
| # 'stem': 'derivation', | ||
| # 'schema': schema_dir / 'derivation-v3.yaml#output', | ||
| # 'files' : [ | ||
| # 'output-caFixedFlat.json', | ||
| # 'output-caFixedNAR.json', | ||
| # 'output-caFixedText.json', | ||
| # 'output-caFloating.json', | ||
| # 'output-deferred.json', | ||
| # 'output-impure.json', | ||
| # 'output-inputAddressed.json', | ||
| # ], | ||
| # }, |
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 think this is fine for now. If we can't get a better solution / get an upstream fix to jv, when I later improve the derivation output schema, I will just move it to separate file(s) so this works.
| `nix derivation add` takes a single derivation in the JSON format. | ||
| See [the manual](@docroot@/protocols/json/derivation.md) for a documentation of this format. |
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 figured whatever markdown was being generated looked pretty fancy, and it is probably too fancy for the man page.
| {{#include ../../protocols/json/derivation.md}} | ||
|
|
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.
(Same as above)
| # For some reason, backticks in the JSON schema are being escaped rather | ||
| # than being kept as intentional code spans. This removes all backtick | ||
| # escaping, which is an ugly solution, but one that is fine, because we | ||
| # are not using backticks for any other purpose. | ||
| s/\\`/`/g |
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.
We should make an upstream issue about this, but that can happen later
| > **Example** | ||
| > | ||
| > ```json | ||
| > "outputs": { | ||
| > "out": { | ||
| > "method": "nar", | ||
| > "hashAlgo": "sha256", | ||
| > "hash": "6fc80dcc62179dbc12fc0b5881275898f93444833d21b89dfe5f7fbcbb1d0d62" | ||
| > } | ||
| > } | ||
| > ``` |
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.
JSON Schema is supposed to support examples, but they were not rendering so I just did this instead.
| output: | ||
| type: object | ||
| properties: | ||
| path: | ||
| type: string | ||
| description: | | ||
| The output path, if known in advance. | ||
| method: | ||
| type: string | ||
| enum: [flat, nar, text, git] | ||
| description: | | ||
| For an output which will be [content addressed](@docroot@/store/derivation/outputs/content-address.md), a string representing the [method](@docroot@/store/store-object/content-address.md) of content addressing that is chosen. | ||
| Valid method strings are: | ||
| - [`flat`](@docroot@/store/store-object/content-address.md#method-flat) | ||
| - [`nar`](@docroot@/store/store-object/content-address.md#method-nix-archive) | ||
| - [`text`](@docroot@/store/store-object/content-address.md#method-text) | ||
| - [`git`](@docroot@/store/store-object/content-address.md#method-git) | ||
| hashAlgo: | ||
| "$ref": "./hash-v1.yaml#/$defs/algorithm" | ||
|
|
||
| hash: | ||
| type: string | ||
| description: | | ||
| For fixed-output derivations, the expected content hash in base-16. |
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.
We could do a better sum type than this for sure, but I just kept it like this for now because it matches how the old manually-written docs were.
| with_footer: false | ||
| recursive_detection_depth: 3 | ||
| show_breadcrumbs: false | ||
| description_is_markdown: true |
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 was hoping this would fix the backtick issue, but it did not.
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.
Figured it out: only happens when the description gets used in place of our missing title.
By providing titles we get a brief ToC in the table, and the rest of the content in its own section, without formatting messes.
I've also opened coveooss/json-schema-for-humans#319 to make that relation impossible to miss.
| <!-- | ||
| ## Raw Schema | ||
| [JSON Schema for Hash v1](schema/hash-v1.json) | ||
| --> |
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.
It would be nice to generate the raw JSON from the YAML, but I didn't do that yet. I think it can wait.
(We could also go back to JSON from YAML for the source files, but I think that is a bit bad for git diffs and multi-line strings.
| type: object | ||
| description: | | ||
| Information about the output paths of the derivation. | ||
| This is a JSON object with one member per output, where the key is the output name and the value is a JSON object as described. |
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.
We could borrow the technical term from the JSON guidelines,
| This is a JSON object with one member per output, where the key is the output name and the value is a JSON object as described. | |
| This JSON object is a dictionary with one member per output, where the key is the output name and the value is a JSON object as described. |
or use a less explicit but more natural term:
| This is a JSON object with one member per output, where the key is the output name and the value is a JSON object as described. | |
| This JSON object is a mapping with one member per output, where the key is the output name and the value is a JSON object as described. |
| with_footer: false | ||
| recursive_detection_depth: 3 | ||
| show_breadcrumbs: false | ||
| description_is_markdown: true |
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.
Figured it out: only happens when the description gets used in place of our missing title.
By providing titles we get a brief ToC in the table, and the rest of the content in its own section, without formatting messes.
I've also opened coveooss/json-schema-for-humans#319 to make that relation impossible to miss.
This way, the description isn't rendered in the tables of contents, leading to no more formatting errors.
|
Since we both worked on this, your contributions (and I think mine) LGTM! |
Motivation
Let's be serious about JSON.
Adds a python tool to the manual build.
Example validation is a separate check; not part of the
nixpackage. Runs in CI.Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.