Skip to content

Commit f63bb5b

Browse files
authored
Merge pull request #14427 from obsidiansystems/drv-output-better-schema
Better JSON schema for derivation outputs
2 parents 7c85ac2 + c2609df commit f63bb5b

File tree

2 files changed

+163
-28
lines changed

2 files changed

+163
-28
lines changed

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

Lines changed: 110 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ properties:
6868
> }
6969
> ```
7070
additionalProperties:
71-
"$ref": "#/$defs/output"
71+
"$ref": "#/$defs/output/overall"
7272

7373
inputSrcs:
7474
type: array
@@ -154,28 +154,116 @@ properties:
154154

155155
"$defs":
156156
output:
157-
type: object
158-
properties:
159-
path:
160-
$ref: "store-path-v1.yaml"
161-
title: Output path
162-
description: |
163-
The output path, if known in advance.
157+
overall:
158+
title: Derivation Output
159+
description: |
160+
A single output of a derivation, with different variants for different output types.
161+
oneOf:
162+
- "$ref": "#/$defs/output/inputAddressed"
163+
- "$ref": "#/$defs/output/caFixed"
164+
- "$ref": "#/$defs/output/caFloating"
165+
- "$ref": "#/$defs/output/deferred"
166+
- "$ref": "#/$defs/output/impure"
164167

165-
method:
166-
"$ref": "./content-address-v1.yaml#/$defs/method"
167-
description: |
168-
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.
169-
See the linked original definition for further details.
170-
hashAlgo:
171-
title: Hash algorithm
172-
"$ref": "./hash-v1.yaml#/$defs/algorithm"
173-
174-
hash:
175-
type: string
176-
title: Expected hash value
177-
description: |
178-
For fixed-output derivations, the expected content hash in base-16.
168+
inputAddressed:
169+
title: Input-Addressed Output
170+
description: |
171+
The traditional non-fixed-output derivation type.
172+
The output path is determined from the derivation itself.
173+
174+
See [Input-addressing derivation outputs](@docroot@/store/derivation/outputs/input-address.md) for more details.
175+
type: object
176+
required:
177+
- path
178+
properties:
179+
path:
180+
$ref: "store-path-v1.yaml"
181+
title: Output path
182+
description: |
183+
The output path determined from the derivation itself.
184+
additionalProperties: false
185+
186+
caFixed:
187+
title: Fixed Content-Addressed Output
188+
description: |
189+
The output is content-addressed, and the content-address is fixed in advance.
190+
191+
See [Fixed-output content-addressing](@docroot@/store/derivation/outputs/content-address.md#fixed) for more details.
192+
type: object
193+
required:
194+
- method
195+
- hashAlgo
196+
- hash
197+
properties:
198+
method:
199+
"$ref": "./content-address-v1.yaml#/$defs/method"
200+
description: |
201+
Method of content addressing used for this output.
202+
hashAlgo:
203+
title: Hash algorithm
204+
"$ref": "./hash-v1.yaml#/$defs/algorithm"
205+
hash:
206+
type: string
207+
title: Expected hash value
208+
description: |
209+
The expected content hash in base-16.
210+
additionalProperties: false
211+
212+
caFloating:
213+
title: Floating Content-Addressed Output
214+
description: |
215+
Floating-output derivations, whose outputs are content
216+
addressed, but not fixed, and so the output paths are dynamically calculated from
217+
whatever the output ends up being.
218+
219+
See [Floating Content-Addressing](@docroot@/store/derivation/outputs/content-address.md#floating) for more details.
220+
type: object
221+
required:
222+
- method
223+
- hashAlgo
224+
properties:
225+
method:
226+
"$ref": "./content-address-v1.yaml#/$defs/method"
227+
description: |
228+
Method of content addressing used for this output.
229+
hashAlgo:
230+
title: Hash algorithm
231+
"$ref": "./hash-v1.yaml#/$defs/algorithm"
232+
description: |
233+
What hash algorithm to use for the given method of content-addressing.
234+
additionalProperties: false
235+
236+
deferred:
237+
title: Deferred Output
238+
description: |
239+
Input-addressed output which depends on a (CA) derivation whose outputs (and thus their content-address
240+
are not yet known.
241+
type: object
242+
properties: {}
243+
additionalProperties: false
244+
245+
impure:
246+
title: Impure Output
247+
description: |
248+
Impure output which is just like a floating content-addressed output, but this derivation runs without sandboxing.
249+
As such, we don't record it in the build trace, under the assumption that if we need it again, we should rebuild it, as it might produce something different.
250+
required:
251+
- impure
252+
- method
253+
- hashAlgo
254+
properties:
255+
impure:
256+
const: true
257+
method:
258+
"$ref": "./content-address-v1.yaml#/$defs/method"
259+
description: |
260+
How the file system objects will be serialized for hashing.
261+
hashAlgo:
262+
title: Hash algorithm
263+
"$ref": "./hash-v1.yaml#/$defs/algorithm"
264+
description: |
265+
How the serialization will be hashed.
266+
additionalProperties: false
179267

180268
outputName:
181269
type: string

src/json-schema-checks/meson.build

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ schemas = [
4545
'simple.json',
4646
],
4747
},
48+
{
49+
'stem' : 'deriving-path',
50+
'schema' : schema_dir / 'deriving-path-v1.yaml',
51+
'files' : [
52+
'single_opaque.json',
53+
'single_built.json',
54+
'single_built_built.json',
55+
],
56+
},
57+
]
58+
59+
# Derivation and Derivation output
60+
schemas += [
61+
# Match overall
4862
{
4963
'stem' : 'derivation',
5064
'schema' : schema_dir / 'derivation-v3.yaml',
@@ -55,7 +69,7 @@ schemas = [
5569
},
5670
{
5771
'stem' : 'derivation',
58-
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output',
72+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/overall',
5973
'files' : [
6074
'output-caFixedFlat.json',
6175
'output-caFixedNAR.json',
@@ -66,15 +80,48 @@ schemas = [
6680
'output-inputAddressed.json',
6781
],
6882
},
83+
# Match exact variant
6984
{
70-
'stem' : 'deriving-path',
71-
'schema' : schema_dir / 'deriving-path-v1.yaml',
85+
'stem' : 'derivation',
86+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/inputAddressed',
7287
'files' : [
73-
'single_opaque.json',
74-
'single_built.json',
75-
'single_built_built.json',
88+
'output-inputAddressed.json',
89+
],
90+
},
91+
{
92+
'stem' : 'derivation',
93+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/caFixed',
94+
'files' : [
95+
'output-caFixedFlat.json',
96+
'output-caFixedNAR.json',
97+
'output-caFixedText.json',
98+
],
99+
},
100+
{
101+
'stem' : 'derivation',
102+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/caFloating',
103+
'files' : [
104+
'output-caFloating.json',
105+
],
106+
},
107+
{
108+
'stem' : 'derivation',
109+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/deferred',
110+
'files' : [
111+
'output-deferred.json',
112+
],
113+
},
114+
{
115+
'stem' : 'derivation',
116+
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output/impure',
117+
'files' : [
118+
'output-impure.json',
76119
],
77120
},
121+
]
122+
123+
# Store object info
124+
schemas += [
78125
# Match overall
79126
{
80127
'stem' : 'store-object-info',

0 commit comments

Comments
 (0)