Skip to content

Commit caa196e

Browse files
committed
Make the store path info ca field structured in JSON
The old string format is a holdover from the pre JSON days. It is not friendly to users who need to get the information out of it. Also introduce the sort of versioning we have for derivation for this format too.
1 parent 0c37a62 commit caa196e

File tree

17 files changed

+130
-36
lines changed

17 files changed

+130
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ schemas = [
1212
'hash-v1',
1313
'content-address-v1',
1414
'store-path-v1',
15-
'store-object-info-v1',
15+
'store-object-info-v2',
1616
'derivation-v4',
1717
'deriving-path-v1',
1818
'build-trace-entry-v1',

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
-->

src/json-schema-checks/meson.build

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ schemas += [
134134
# Match overall
135135
{
136136
'stem' : 'store-object-info',
137-
'schema' : schema_dir / 'store-object-info-v1.yaml',
137+
'schema' : schema_dir / 'store-object-info-v2.yaml',
138138
'files' : [
139139
'pure.json',
140140
'impure.json',
@@ -144,7 +144,7 @@ schemas += [
144144
},
145145
{
146146
'stem' : 'nar-info',
147-
'schema' : schema_dir / 'store-object-info-v1.yaml',
147+
'schema' : schema_dir / 'store-object-info-v2.yaml',
148148
'files' : [
149149
'pure.json',
150150
'impure.json',
@@ -162,30 +162,30 @@ schemas += [
162162
# Match exact variant
163163
{
164164
'stem' : 'store-object-info',
165-
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/base',
165+
'schema' : schema_dir / 'store-object-info-v2.yaml#/$defs/base',
166166
'files' : [
167167
'pure.json',
168168
'empty_pure.json',
169169
],
170170
},
171171
{
172172
'stem' : 'store-object-info',
173-
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/impure',
173+
'schema' : schema_dir / 'store-object-info-v2.yaml#/$defs/impure',
174174
'files' : [
175175
'impure.json',
176176
'empty_impure.json',
177177
],
178178
},
179179
{
180180
'stem' : 'nar-info',
181-
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/base',
181+
'schema' : schema_dir / 'store-object-info-v2.yaml#/$defs/base',
182182
'files' : [
183183
'pure.json',
184184
],
185185
},
186186
{
187187
'stem' : 'nar-info',
188-
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/narInfo',
188+
'schema' : schema_dir / 'store-object-info-v2.yaml#/$defs/narInfo',
189189
'files' : [
190190
'impure.json',
191191
],

src/libstore-tests/data/nar-info/impure.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
2-
"ca": "fixed:r:sha256:1lr187v6dck1rjh2j6svpikcfz53wyl3qrlcbb405zlh13x0khhh",
2+
"ca": {
3+
"hash": {
4+
"algorithm": "sha256",
5+
"format": "base64",
6+
"hash": "EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM="
7+
},
8+
"method": "nar"
9+
},
310
"compression": "xz",
411
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
512
"downloadHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
@@ -16,5 +23,6 @@
1623
"qwer"
1724
],
1825
"ultimate": true,
19-
"url": "nar/1w1fff338fvdw53sqgamddn1b2xgds473pv6y13gizdbqjv4i5p3.nar.xz"
26+
"url": "nar/1w1fff338fvdw53sqgamddn1b2xgds473pv6y13gizdbqjv4i5p3.nar.xz",
27+
"version": 2
2028
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
{
2-
"ca": "fixed:r:sha256:1lr187v6dck1rjh2j6svpikcfz53wyl3qrlcbb405zlh13x0khhh",
2+
"ca": {
3+
"hash": {
4+
"algorithm": "sha256",
5+
"format": "base64",
6+
"hash": "EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM="
7+
},
8+
"method": "nar"
9+
},
310
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
411
"narSize": 34878,
512
"references": [
613
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
714
"/nix/store/n5wkd9frr45pa74if5gpz9j7mifg27fh-foo"
8-
]
15+
],
16+
"version": 2
917
}

src/libstore-tests/data/path-info/empty_impure.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"references": [],
77
"registrationTime": null,
88
"signatures": [],
9-
"ultimate": false
9+
"ultimate": false,
10+
"version": 2
1011
}

src/libstore-tests/data/path-info/empty_pure.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"ca": null,
33
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
44
"narSize": 0,
5-
"references": []
5+
"references": [],
6+
"version": 2
67
}

src/libstore-tests/data/path-info/impure.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
2-
"ca": "fixed:r:sha256:1lr187v6dck1rjh2j6svpikcfz53wyl3qrlcbb405zlh13x0khhh",
2+
"ca": {
3+
"hash": {
4+
"algorithm": "sha256",
5+
"format": "base64",
6+
"hash": "EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM="
7+
},
8+
"method": "nar"
9+
},
310
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
411
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
512
"narSize": 34878,
@@ -12,5 +19,6 @@
1219
"asdf",
1320
"qwer"
1421
],
15-
"ultimate": true
22+
"ultimate": true,
23+
"version": 2
1624
}

0 commit comments

Comments
 (0)