Skip to content

Commit 912448d

Browse files
committed
JSON Schema for DerivationOutputs
Progress on #13570
1 parent 70b9fbd commit 912448d

File tree

9 files changed

+310
-1
lines changed

9 files changed

+310
-1
lines changed

doc/manual/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ manual = custom_target(
8888
@0@ @INPUT0@ @CURRENT_SOURCE_DIR@ > @DEPFILE@
8989
@0@ @INPUT1@ summary @2@ < @CURRENT_SOURCE_DIR@/source/SUMMARY.md.in > @2@/source/SUMMARY.md
9090
sed -e 's|@version@|@3@|g' < @INPUT2@ > @2@/book.toml
91-
@4@ -r -L --include='*.md' @CURRENT_SOURCE_DIR@/ @2@/
91+
@4@ -r -L --exclude='*.drv' --include='*.md' @CURRENT_SOURCE_DIR@/ @2@/
9292
(cd @2@; RUST_LOG=warn @1@ build -d @2@ 3>&2 2>&1 1>&3) | { grep -Fv "because fragment resolution isn't implemented" || :; } 3>&2 2>&1 1>&3
9393
rm -rf @2@/manual
9494
mv @2@/html @2@/manual

doc/manual/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mkMesonDerivation (finalAttrs: {
4141
../../src/libstore-tests/data/content-address
4242
../../src/libstore-tests/data/store-path
4343
../../src/libstore-tests/data/realisation
44+
../../src/libstore-tests/data/derivation
4445
../../src/libstore-tests/data/derived-path
4546
../../src/libstore-tests/data/path-info
4647
../../src/libstore-tests/data/nar-info

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
- [Store Path](protocols/json/store-path.md)
127127
- [Store Object Info](protocols/json/store-object-info.md)
128128
- [Derivation](protocols/json/derivation.md)
129+
- [Derivation Options](protocols/json/derivation-options.md)
129130
- [Deriving Path](protocols/json/deriving-path.md)
130131
- [Build Trace Entry](protocols/json/build-trace-entry.md)
131132
- [Build Result](protocols/json/build-result.md)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{#include derivation-options-v1-fixed.md}}
2+
3+
## Examples
4+
5+
### Input-addressed derivations
6+
7+
#### Default options
8+
9+
```json
10+
{{#include schema/derivation-options-v1/ia/defaults.json}}
11+
```
12+
13+
#### All options set
14+
15+
```json
16+
{{#include schema/derivation-options-v1/ia/all_set.json}}
17+
```
18+
19+
#### Default options (structured attributes)
20+
21+
```json
22+
{{#include schema/derivation-options-v1/ia/structuredAttrs_defaults.json}}
23+
```
24+
25+
#### All options set (structured attributes)
26+
27+
```json
28+
{{#include schema/derivation-options-v1/ia/structuredAttrs_all_set.json}}
29+
```
30+
31+
### Content-addressed derivations
32+
33+
#### All options set
34+
35+
```json
36+
{{#include schema/derivation-options-v1/ca/all_set.json}}
37+
```
38+
39+
#### All options set (structured attributes)
40+
41+
```json
42+
{{#include schema/derivation-options-v1/ca/structuredAttrs_all_set.json}}
43+
```
44+
45+
<!-- need to convert YAML to JSON first
46+
## Raw Schema
47+
48+
[JSON Schema for Derivation Options v1](schema/derivation-options-v1.json)
49+
-->

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ schemas = [
1414
'store-path-v1',
1515
'store-object-info-v2',
1616
'derivation-v4',
17+
'derivation-options-v1',
1718
'deriving-path-v1',
1819
'build-trace-entry-v1',
1920
'build-result-v1',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libstore-tests/data/derivation
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-options-v1.json"
3+
title: Derivation Options
4+
description: |
5+
JSON representation of Nix's `DerivationOptions` type.
6+
7+
This schema describes various build-time options and constraints that can be specified for a derivation.
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+
type: object
16+
required:
17+
- outputChecks
18+
- unsafeDiscardReferences
19+
- passAsFile
20+
- exportReferencesGraph
21+
- additionalSandboxProfile
22+
- noChroot
23+
- impureHostDeps
24+
- impureEnvVars
25+
- allowLocalNetworking
26+
- requiredSystemFeatures
27+
- preferLocalBuild
28+
- allowSubstitutes
29+
properties:
30+
outputChecks:
31+
type: object
32+
title: Output Check
33+
description: |
34+
Constraints on what the derivation's outputs can and cannot reference.
35+
Can either apply to all outputs or be specified per output.
36+
oneOf:
37+
- title: Output Checks For All Outputs
38+
description: |
39+
Output checks that apply to all outputs of the derivation.
40+
required:
41+
- forAllOutputs
42+
properties:
43+
forAllOutputs:
44+
"$ref": "#/$defs/outputCheckSpec"
45+
additionalProperties: false
46+
47+
- title: Output Checks Per Output
48+
description: |
49+
Output checks specified individually for each output.
50+
required:
51+
- perOutput
52+
properties:
53+
perOutput:
54+
type: object
55+
additionalProperties:
56+
"$ref": "#/$defs/outputCheckSpec"
57+
additionalProperties: false
58+
59+
unsafeDiscardReferences:
60+
type: object
61+
title: Unsafe Discard References
62+
description: |
63+
A map specifying which references should be unsafely discarded from each output.
64+
This is generally not recommended and requires special permissions.
65+
additionalProperties:
66+
type: array
67+
items:
68+
type: string
69+
70+
passAsFile:
71+
type: array
72+
title: Pass As File
73+
description: |
74+
List of environment variable names whose values should be passed as files rather than directly.
75+
items:
76+
type: string
77+
78+
exportReferencesGraph:
79+
type: object
80+
title: Export References Graph
81+
description: |
82+
Specify paths whose references graph should be exported to files.
83+
additionalProperties:
84+
type: array
85+
items:
86+
"$ref": "deriving-path-v1.yaml"
87+
88+
additionalSandboxProfile:
89+
type: string
90+
title: Additional Sandbox Profile
91+
description: |
92+
Additional sandbox profile directives (macOS specific).
93+
94+
noChroot:
95+
type: boolean
96+
title: No Chroot
97+
description: |
98+
Whether to disable the build sandbox, if allowed.
99+
100+
impureHostDeps:
101+
type: array
102+
title: Impure Host Dependencies
103+
description: |
104+
List of host paths that the build can access.
105+
items:
106+
type: string
107+
108+
impureEnvVars:
109+
type: array
110+
title: Impure Environment Variables
111+
description: |
112+
List of environment variable names that should be passed through to the build from the calling environment.
113+
items:
114+
type: string
115+
116+
allowLocalNetworking:
117+
type: boolean
118+
title: Allow Local Networking
119+
description: |
120+
Whether the build should have access to local network (macOS specific).
121+
122+
requiredSystemFeatures:
123+
type: array
124+
title: Required System Features
125+
description: |
126+
List of system features required to build this derivation (e.g., "kvm", "nixos-test").
127+
items:
128+
type: string
129+
130+
preferLocalBuild:
131+
type: boolean
132+
title: Prefer Local Build
133+
description: |
134+
Whether this derivation should preferably be built locally rather than its outputs substituted.
135+
136+
allowSubstitutes:
137+
type: boolean
138+
title: Allow Substitutes
139+
description: |
140+
Whether substituting from other stores should be allowed for this derivation's outputs.
141+
142+
additionalProperties: false
143+
144+
$defs:
145+
146+
outputCheckSpec:
147+
type: object
148+
title: Output Check Specification
149+
description: |
150+
Constraints on what a specific output can reference.
151+
required:
152+
- ignoreSelfRefs
153+
- maxSize
154+
- maxClosureSize
155+
- allowedReferences
156+
- allowedRequisites
157+
- disallowedReferences
158+
- disallowedRequisites
159+
properties:
160+
ignoreSelfRefs:
161+
type: boolean
162+
title: Ignore Self References
163+
description: |
164+
Whether references from this output to itself should be ignored when checking references.
165+
166+
maxSize:
167+
type: ["integer", "null"]
168+
title: Maximum Size
169+
description: |
170+
Maximum allowed size of this output in bytes, or null for no limit.
171+
minimum: 0
172+
173+
maxClosureSize:
174+
type: ["integer", "null"]
175+
title: Maximum Closure Size
176+
description: |
177+
Maximum allowed size of this output's closure in bytes, or null for no limit.
178+
minimum: 0
179+
180+
allowedReferences:
181+
oneOf:
182+
- type: array
183+
items:
184+
"$ref": "#/$defs/drvRef"
185+
- type: "null"
186+
title: Allowed References
187+
description: |
188+
If set, the output can only reference paths in this list.
189+
If null, no restrictions apply.
190+
191+
allowedRequisites:
192+
oneOf:
193+
- type: array
194+
items:
195+
"$ref": "#/$defs/drvRef"
196+
- type: "null"
197+
title: Allowed Requisites
198+
description: |
199+
If set, the output's closure can only contain paths in this list.
200+
If null, no restrictions apply.
201+
202+
disallowedReferences:
203+
type: array
204+
title: Disallowed References
205+
description: |
206+
The output must not reference any paths in this list.
207+
items:
208+
"$ref": "#/$defs/drvRef"
209+
210+
disallowedRequisites:
211+
type: array
212+
title: Disallowed Requisites
213+
description: |
214+
The output's closure must not contain any paths in this list.
215+
items:
216+
"$ref": "#/$defs/drvRef"
217+
additionalProperties: false
218+
219+
drvRef:
220+
# TODO fix bug in checker, should be `oneOf`
221+
anyOf:
222+
- type: object
223+
title: Current derivation Output Reference
224+
description: |
225+
A reference to a specific output of the current derivation.
226+
required:
227+
- drvPath
228+
- output
229+
properties:
230+
drvPath:
231+
type: string
232+
const: "self"
233+
title: This derivation
234+
description: |
235+
Won't be confused for a deriving path
236+
output:
237+
type: string
238+
title: Output Name
239+
description: |
240+
The name of the output being referenced.
241+
additionalProperties: false
242+
- "$ref": "deriving-path-v1.yaml"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../libstore-tests/data/derivation

src/json-schema-checks/meson.build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ schemas = [
6363
'with-signature.json',
6464
],
6565
},
66+
# Derivation options
67+
{
68+
'stem' : 'derivation-options',
69+
'schema' : schema_dir / 'derivation-options-v1.yaml',
70+
'files' : [
71+
'ia' / 'defaults.json',
72+
'ia' / 'all_set.json',
73+
'ia' / 'structuredAttrs_defaults.json',
74+
'ia' / 'structuredAttrs_all_set.json',
75+
'ca' / 'all_set.json',
76+
'ca' / 'structuredAttrs_all_set.json',
77+
],
78+
},
6679
]
6780

6881
# Derivation and Derivation output

0 commit comments

Comments
 (0)