Skip to content

Commit 5b15544

Browse files
authored
Merge pull request #14493 from obsidiansystems/drv-and-path-info-new-fmts
Modifications to the JSON formats for `Derivation` and `ValidPathInfo`
2 parents 147e183 + 8cc3ede commit 5b15544

37 files changed

+475
-287
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
synopsis: "JSON format changes for store path info and derivations"
3+
prs: []
4+
issues: []
5+
---
6+
7+
JSON formats for store path info and derivations have been updated with new versions and structured fields.
8+
9+
## Store Path Info JSON (Version 2)
10+
11+
The store path info JSON format has been updated from version 1 to version 2:
12+
13+
- **Added `version` field**:
14+
15+
All store path info JSON now includes `"version": 2`.
16+
17+
- **Structured `ca` field**:
18+
19+
Content address is now a structured JSON object instead of a string:
20+
21+
- Old: `"ca": "fixed:r:sha256:1abc..."`
22+
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
23+
- Still `null` values for input-addressed store objects
24+
25+
Version 1 format is still accepted when reading for backward compatibility.
26+
27+
**Affected command**: `nix path-info --json`
28+
29+
## Derivation JSON (Version 4)
30+
31+
The derivation JSON format has been updated from version 3 to version 4:
32+
33+
- **Restructured inputs**:
34+
35+
Inputs are now nested under an `inputs` object:
36+
37+
- Old: `"inputSrcs": [...], "inputDrvs": {...}`
38+
- New: `"inputs": {"srcs": [...], "drvs": {...}}`
39+
40+
- **Consistent content addresses**:
41+
42+
Floating content-addressed outputs now use structured JSON format.
43+
This is the same format as `ca` in in store path info (after the new version).
44+
45+
Version 3 and earlier formats are *not* accepted when reading.
46+
47+
**Affected command**: `nix derivation`, namely it's `show` and `add` sub-commands.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{{#include derivation-v3-fixed.md}}
1+
{{#include derivation-v4-fixed.md}}
22

33
<!-- need to convert YAML to JSON first
44
## Raw Schema
55
6-
[JSON Schema for Derivation v3](schema/derivation-v3.json)
6+
[JSON Schema for Derivation v3](schema/derivation-v4.json)
77
-->

doc/manual/source/protocols/json/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ schemas = [
1212
'hash-v1',
1313
'content-address-v1',
1414
'store-path-v1',
15-
'store-object-info-v1',
16-
'derivation-v3',
15+
'store-object-info-v2',
16+
'derivation-v4',
1717
'deriving-path-v1',
1818
'build-trace-entry-v1',
1919
'build-result-v1',

doc/manual/source/protocols/json/schema/derivation-v3.yaml renamed to doc/manual/source/protocols/json/schema/derivation-v4.yaml

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"$schema": "http://json-schema.org/draft-04/schema"
2-
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v4.json"
33
title: Derivation
44
description: |
5-
Experimental JSON representation of a Nix derivation (version 3).
5+
Experimental JSON representation of a Nix derivation (version 4).
66
77
This schema describes the JSON representation of Nix's `Derivation` type.
88
@@ -17,8 +17,7 @@ required:
1717
- name
1818
- version
1919
- outputs
20-
- inputSrcs
21-
- inputDrvs
20+
- inputs
2221
- system
2322
- builder
2423
- args
@@ -32,10 +31,10 @@ properties:
3231
Used when calculating store paths for the derivation’s outputs.
3332
3433
version:
35-
const: 3
36-
title: Format version (must be 3)
34+
const: 4
35+
title: Format version (must be 4)
3736
description: |
38-
Must be `3`.
37+
Must be `4`.
3938
This is a guard that allows us to continue evolving this format.
4039
The choice of `3` is fairly arbitrary, but corresponds to this informal version:
4140
@@ -47,6 +46,12 @@ properties:
4746
4847
- Version 3: Drop store dir from store paths, just include base name.
4948
49+
- Version 4: Two cleanups, batched together to lesson churn:
50+
51+
- Reorganize inputs into nested structure (`inputs.srcs` and `inputs.drvs`)
52+
53+
- Use canonical content address JSON format for floating content addressed derivation outputs.
54+
5055
Note that while this format is experimental, the maintenance of versions is best-effort, and not promised to identify every change.
5156
5257
outputs:
@@ -70,47 +75,56 @@ properties:
7075
additionalProperties:
7176
"$ref": "#/$defs/output/overall"
7277

73-
inputSrcs:
74-
type: array
75-
title: Input source paths
76-
description: |
77-
List of store paths on which this derivation depends.
78-
79-
> **Example**
80-
>
81-
> ```json
82-
> "inputSrcs": [
83-
> "47y241wqdhac3jm5l7nv0x4975mb1975-separate-debug-info.sh",
84-
> "56d0w71pjj9bdr363ym3wj1zkwyqq97j-fix-pop-var-context-error.patch"
85-
> ]
86-
> ```
87-
items:
88-
$ref: "store-path-v1.yaml"
89-
90-
inputDrvs:
78+
inputs:
9179
type: object
92-
title: Input derivations
80+
title: Derivation inputs
9381
description: |
94-
Mapping of derivation paths to lists of output names they provide.
95-
96-
> **Example**
97-
>
98-
> ```json
99-
> "inputDrvs": {
100-
> "6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
101-
> "fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
102-
> }
103-
> ```
104-
>
105-
> specifies that this derivation depends on the `dev` output of `curl`, and the `out` output of `unzip`.
106-
patternProperties:
107-
"^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+\\.drv$":
108-
title: Store Path
82+
Input dependencies for the derivation, organized into source paths and derivation dependencies.
83+
required:
84+
- srcs
85+
- drvs
86+
properties:
87+
srcs:
88+
type: array
89+
title: Input source paths
90+
description: |
91+
List of store paths on which this derivation depends.
92+
93+
> **Example**
94+
>
95+
> ```json
96+
> "srcs": [
97+
> "47y241wqdhac3jm5l7nv0x4975mb1975-separate-debug-info.sh",
98+
> "56d0w71pjj9bdr363ym3wj1zkwyqq97j-fix-pop-var-context-error.patch"
99+
> ]
100+
> ```
101+
items:
102+
$ref: "store-path-v1.yaml"
103+
drvs:
104+
type: object
105+
title: Input derivations
109106
description: |
110-
A store path to a derivation, mapped to the outputs of that derivation.
111-
oneOf:
112-
- "$ref": "#/$defs/outputNames"
113-
- "$ref": "#/$defs/dynamicOutputs"
107+
Mapping of derivation paths to lists of output names they provide.
108+
109+
> **Example**
110+
>
111+
> ```json
112+
> "drvs": {
113+
> "6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
114+
> "fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
115+
> }
116+
> ```
117+
>
118+
> specifies that this derivation depends on the `dev` output of `curl`, and the `out` output of `unzip`.
119+
patternProperties:
120+
"^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+\\.drv$":
121+
title: Store Path
122+
description: |
123+
A store path to a derivation, mapped to the outputs of that derivation.
124+
oneOf:
125+
- "$ref": "#/$defs/outputNames"
126+
- "$ref": "#/$defs/dynamicOutputs"
127+
additionalProperties: false
114128
additionalProperties: false
115129

116130
system:
@@ -189,24 +203,18 @@ properties:
189203
The output is content-addressed, and the content-address is fixed in advance.
190204
191205
See [Fixed-output content-addressing](@docroot@/store/derivation/outputs/content-address.md#fixed) for more details.
192-
type: object
206+
"$ref": "./content-address-v1.yaml"
193207
required:
194208
- method
195-
- hashAlgo
196209
- hash
197210
properties:
198211
method:
199-
"$ref": "./content-address-v1.yaml#/$defs/method"
200212
description: |
201213
Method of content addressing used for this output.
202-
hashAlgo:
203-
title: Hash algorithm
204-
"$ref": "./hash-v1.yaml#/$defs/algorithm"
205214
hash:
206-
type: string
207215
title: Expected hash value
208216
description: |
209-
The expected content hash in base-16.
217+
The expected content hash.
210218
additionalProperties: false
211219

212220
caFloating:

doc/manual/source/protocols/json/schema/store-object-info-v1.yaml renamed to doc/manual/source/protocols/json/schema/store-object-info-v2.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"$schema": "http://json-schema.org/draft-07/schema"
2-
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/store-object-info-v1.json"
3-
title: Store Object Info
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/store-object-info-v2.json"
3+
title: Store Object Info v2
44
description: |
55
Information about a [store object](@docroot@/store/store-object.md).
66
@@ -41,11 +41,27 @@ $defs:
4141
This is the minimal set of fields that describe what a store object contains.
4242
type: object
4343
required:
44+
- version
4445
- narHash
4546
- narSize
4647
- references
4748
- ca
4849
properties:
50+
version:
51+
type: integer
52+
const: 2
53+
title: Format version (must be 2)
54+
description: |
55+
Must be `2`.
56+
This is a guard that allows us to continue evolving this format.
57+
Here is the rough version history:
58+
59+
- Version 0: `.narinfo` line-oriented format
60+
61+
- Version 1: Original JSON format, with ugly `"r:sha256"` inherited from `.narinfo` format.
62+
63+
- Version 2: Use structured JSON type for `ca`
64+
4965
path:
5066
type: string
5167
title: Store Path
@@ -76,7 +92,10 @@ $defs:
7692
type: string
7793

7894
ca:
79-
type: ["string", "null"]
95+
oneOf:
96+
- type: "null"
97+
const: null
98+
- "$ref": "./content-address-v1.yaml"
8099
title: Content Address
81100
description: |
82101
If the store object is [content-addressed](@docroot@/store/store-object/content-address.md),
@@ -91,6 +110,7 @@ $defs:
91110
In other words, the same store object in different stores could have different values for these impure fields.
92111
type: object
93112
required:
113+
- version
94114
- narHash
95115
- narSize
96116
- references
@@ -101,6 +121,7 @@ $defs:
101121
- ultimate
102122
- signatures
103123
properties:
124+
version: { $ref: "#/$defs/base/properties/version" }
104125
path: { $ref: "#/$defs/base/properties/path" }
105126
narHash: { $ref: "#/$defs/base/properties/narHash" }
106127
narSize: { $ref: "#/$defs/base/properties/narSize" }
@@ -164,6 +185,7 @@ $defs:
164185
This download information, being specific to how the store object happens to be stored and transferred, is also considered to be non-intrinsic / impure.
165186
type: object
166187
required:
188+
- version
167189
- narHash
168190
- narSize
169191
- references
@@ -179,6 +201,7 @@ $defs:
179201
- downloadHash
180202
- downloadSize
181203
properties:
204+
version: { $ref: "#/$defs/base/properties/version" }
182205
path: { $ref: "#/$defs/base/properties/path" }
183206
narHash: { $ref: "#/$defs/base/properties/narHash" }
184207
narSize: { $ref: "#/$defs/base/properties/narSize" }

doc/manual/source/protocols/json/store-object-info.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
{{#include store-object-info-v1-fixed.md}}
1+
{{#include store-object-info-v2-fixed.md}}
22

33
## Examples
44

55
### Minimal store object (content-addressed)
66

77
```json
8-
{{#include schema/store-object-info-v1/pure.json}}
8+
{{#include schema/store-object-info-v2/pure.json}}
99
```
1010

1111
### Store object with impure fields
1212

1313
```json
14-
{{#include schema/store-object-info-v1/impure.json}}
14+
{{#include schema/store-object-info-v2/impure.json}}
1515
```
1616

1717
### Minimal store object (empty)
1818

1919
```json
20-
{{#include schema/store-object-info-v1/empty_pure.json}}
20+
{{#include schema/store-object-info-v2/empty_pure.json}}
2121
```
2222

2323
### Store object with all impure fields
2424

2525
```json
26-
{{#include schema/store-object-info-v1/empty_impure.json}}
26+
{{#include schema/store-object-info-v2/empty_impure.json}}
2727
```
2828

2929
### NAR info (minimal)
@@ -41,5 +41,5 @@
4141
<!-- need to convert YAML to JSON first
4242
## Raw Schema
4343
44-
[JSON Schema for Store Object Info v1](schema/store-object-info-v1.json)
44+
[JSON Schema for Store Object Info v1](schema/store-object-info-v2.json)
4545
-->

0 commit comments

Comments
 (0)