Skip to content

Commit 6280905

Browse files
committed
Convert store path info JSON docs to formal JSON Schema, and test
This continues the work for formalizing our current JSON docs. Note that in the process, a few bugs were caught: - `closureSize` was repeated twice, forgot `closureDownloadSize` - `file*` fields should be `download*`. They are in fact called that in the line-oriented `.narinfo` file, but were renamed in the JSON format.
1 parent f1d4fab commit 6280905

File tree

13 files changed

+327
-90
lines changed

13 files changed

+327
-90
lines changed

doc/manual/package.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ mkMesonDerivation (finalAttrs: {
3838
../../src/libstore-tests/data/content-address
3939
../../src/libstore-tests/data/store-path
4040
../../src/libstore-tests/data/derived-path
41+
../../src/libstore-tests/data/path-info
42+
../../src/libstore-tests/data/nar-info
4143
# Too many different types of files to filter for now
4244
../../doc/manual
4345
./.

doc/manual/source/protocols/json/derivation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{#include derivation-v3-fixed.md}}
22

3-
<!--
3+
<!-- need to convert YAML to JSON first
44
## Raw Schema
55
66
[JSON Schema for Derivation v3](schema/derivation-v3.json)

doc/manual/source/protocols/json/hash.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{{#include schema/hash-v1/blake3-base64.json}}
2727
```
2828

29-
<!--
29+
<!-- need to convert YAML to JSON first
3030
## Raw Schema
3131
3232
[JSON Schema for Hash v1](schema/hash-v1.json)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ schemas = [
1212
'hash-v1',
1313
'content-address-v1',
1414
'store-path-v1',
15+
'store-object-info-v1',
1516
'derivation-v3',
1617
'deriving-path-v1',
1718
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libstore-tests/data/nar-info
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libstore-tests/data/path-info
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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
4+
description: |
5+
Information about a [store object](@docroot@/store/store-object.md).
6+
7+
This schema describes the JSON representation of store object metadata as returned by commands like [`nix path-info --json`](@docroot@/command-ref/new-cli/nix3-path-info.md).
8+
9+
> **Warning**
10+
>
11+
> This JSON format is currently
12+
> [**experimental**](@docroot@/development/experimental-features.md#xp-feature-nix-command)
13+
> and subject to change.
14+
15+
### Field Categories
16+
17+
Store object information can come in a few different variations.
18+
19+
Firstly, "impure" fields, which contain non-intrinsic information about the store object, may or may not be included.
20+
21+
Second, binary cache stores have extra non-intrinsic infomation about the store objects they contain.
22+
23+
Thirdly, [`nix path-info --json --closure-size`](@docroot@/command-ref/new-cli/nix3-path-info.html#opt-closure-size) can compute some extra information about not just the single store object in question, but the store object and its [closure](@docroot@/glossary.md#gloss-closure).
24+
25+
The impure and NAR fields are grouped into separate variants below.
26+
See their descriptions for additional information.
27+
The closure fields however as just included as optional fields, to avoid a combinatorial explosion of variants.
28+
29+
oneOf:
30+
- $ref: "#/$defs/base"
31+
32+
- $ref: "#/$defs/impure"
33+
34+
- $ref: "#/$defs/narInfo"
35+
36+
$defs:
37+
base:
38+
title: Store Object Info
39+
description: |
40+
Basic store object metadata containing only intrinsic properties.
41+
This is the minimal set of fields that describe what a store object contains.
42+
type: object
43+
required:
44+
- narHash
45+
- narSize
46+
- references
47+
- ca
48+
properties:
49+
path:
50+
type: string
51+
title: Store Path
52+
description: |
53+
[Store path](@docroot@/store/store-path.md) to the given store object.
54+
55+
Note: This field may not be present in all contexts, such as when the path is used as the key and the the store object info the value in map.
56+
57+
narHash:
58+
type: string
59+
title: NAR Hash
60+
description: |
61+
Hash of the [file system object](@docroot@/store/file-system-object.md) part of the store object when serialized as a [Nix Archive](@docroot@/store/file-system-object/content-address.md#serial-nix-archive).
62+
63+
narSize:
64+
type: integer
65+
minimum: 0
66+
title: NAR Size
67+
description: |
68+
Size of the [file system object](@docroot@/store/file-system-object.md) part of the store object when serialized as a [Nix Archive](@docroot@/store/file-system-object/content-address.md#serial-nix-archive).
69+
70+
references:
71+
type: array
72+
title: References
73+
description: |
74+
An array of [store paths](@docroot@/store/store-path.md), possibly including this one.
75+
items:
76+
type: string
77+
78+
ca:
79+
type: ["string", "null"]
80+
title: Content Address
81+
description: |
82+
If the store object is [content-addressed](@docroot@/store/store-object/content-address.md),
83+
this is the content address of this store object's file system object, used to compute its store path.
84+
Otherwise (i.e. if it is [input-addressed](@docroot@/glossary.md#gloss-input-addressed-store-object)), this is `null`.
85+
additionalProperties: false
86+
87+
impure:
88+
title: Store Object Info with Impure Fields
89+
description: |
90+
Store object metadata including impure fields that are not *intrinsic* properties.
91+
In other words, the same store object in different stores could have different values for these impure fields.
92+
type: object
93+
required:
94+
- narHash
95+
- narSize
96+
- references
97+
- ca
98+
# impure
99+
- deriver
100+
- registrationTime
101+
- ultimate
102+
- signatures
103+
properties:
104+
path: { $ref: "#/$defs/base/properties/path" }
105+
narHash: { $ref: "#/$defs/base/properties/narHash" }
106+
narSize: { $ref: "#/$defs/base/properties/narSize" }
107+
references: { $ref: "#/$defs/base/properties/references" }
108+
ca: { $ref: "#/$defs/base/properties/ca" }
109+
deriver:
110+
type: ["string", "null"]
111+
title: Deriver
112+
description: |
113+
If known, the path to the [store derivation](@docroot@/glossary.md#gloss-store-derivation) from which this store object was produced.
114+
Otherwise `null`.
115+
116+
> This is an "impure" field that may not be included in certain contexts.
117+
118+
registrationTime:
119+
type: ["integer", "null"]
120+
title: Registration Time
121+
description: |
122+
If known, when this derivation was added to the store (Unix timestamp).
123+
Otherwise `null`.
124+
125+
> This is an "impure" field that may not be included in certain contexts.
126+
127+
ultimate:
128+
type: boolean
129+
title: Ultimate
130+
description: |
131+
Whether this store object is trusted because we built it ourselves, rather than substituted a build product from elsewhere.
132+
133+
> This is an "impure" field that may not be included in certain contexts.
134+
135+
signatures:
136+
type: array
137+
title: Signatures
138+
description: |
139+
Signatures claiming that this store object is what it claims to be.
140+
Not relevant for [content-addressed](@docroot@/store/store-object/content-address.md) store objects,
141+
but useful for [input-addressed](@docroot@/glossary.md#gloss-input-addressed-store-object) store objects.
142+
143+
> This is an "impure" field that may not be included in certain contexts.
144+
items:
145+
type: string
146+
147+
# Computed closure fields
148+
closureSize:
149+
type: integer
150+
minimum: 0
151+
title: Closure Size
152+
description: |
153+
The total size of this store object and every other object in its [closure](@docroot@/glossary.md#gloss-closure).
154+
155+
> This field is not stored at all, but computed by traversing the other fields across all the store objects in a closure.
156+
additionalProperties: false
157+
158+
narInfo:
159+
title: Store Object Info with Impure fields and NAR Info
160+
description: |
161+
The store object info in the "binary cache" family of Nix store type contain extra information pertaining to *downloads* of the store object in question.
162+
(This store info is called "NAR info", since the downloads take the form of [Nix Archives](@docroot@/store/file-system-object/content-address.md#serial-nix-archive, and the metadata is served in a file with a `.narinfo` extension.)
163+
164+
This download information, being specific to how the store object happens to be stored and transferred, is also considered to be non-intrinsic / impure.
165+
type: object
166+
required:
167+
- narHash
168+
- narSize
169+
- references
170+
- ca
171+
# impure
172+
- deriver
173+
- registrationTime
174+
- ultimate
175+
- signatures
176+
# nar
177+
- url
178+
- compression
179+
- downloadHash
180+
- downloadSize
181+
properties:
182+
path: { $ref: "#/$defs/base/properties/path" }
183+
narHash: { $ref: "#/$defs/base/properties/narHash" }
184+
narSize: { $ref: "#/$defs/base/properties/narSize" }
185+
references: { $ref: "#/$defs/base/properties/references" }
186+
ca: { $ref: "#/$defs/base/properties/ca" }
187+
deriver: { $ref: "#/$defs/impure/properties/deriver" }
188+
registrationTime: { $ref: "#/$defs/impure/properties/registrationTime" }
189+
ultimate: { $ref: "#/$defs/impure/properties/ultimate" }
190+
signatures: { $ref: "#/$defs/impure/properties/signatures" }
191+
closureSize: { $ref: "#/$defs/impure/properties/closureSize" }
192+
url:
193+
type: string
194+
title: URL
195+
description: |
196+
Where to download a compressed archive of the file system objects of this store object.
197+
198+
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
199+
200+
compression:
201+
type: string
202+
title: Compression
203+
description: |
204+
The compression format that the archive is in.
205+
206+
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
207+
208+
downloadHash:
209+
type: string
210+
title: Download Hash
211+
description: |
212+
A digest for the compressed archive itself, as opposed to the data contained within.
213+
214+
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
215+
216+
downloadSize:
217+
type: integer
218+
minimum: 0
219+
title: Download Size
220+
description: |
221+
The size of the compressed archive itself.
222+
223+
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
224+
225+
closureDownloadSize:
226+
type: integer
227+
minimum: 0
228+
title: Closure Download Size
229+
description: |
230+
The total size of the compressed archive itself for this object, and the compressed archive of every object in this object's [closure](@docroot@/glossary.md#gloss-closure).
231+
232+
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
233+
234+
> This field is not stored at all, but computed by traversing the other fields across all the store objects in a closure.
235+
additionalProperties: false

0 commit comments

Comments
 (0)