Skip to content

Commit f1d4fab

Browse files
authored
Merge pull request #14405 from obsidiansystems/json-schema-store-path
Create JSON Schema for Store Paths
2 parents be99a1c + c679664 commit f1d4fab

File tree

11 files changed

+97
-3
lines changed

11 files changed

+97
-3
lines changed

doc/manual/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ mkMesonDerivation (finalAttrs: {
3636
# For example JSON
3737
../../src/libutil-tests/data/hash
3838
../../src/libstore-tests/data/content-address
39+
../../src/libstore-tests/data/store-path
3940
../../src/libstore-tests/data/derived-path
4041
# Too many different types of files to filter for now
4142
../../doc/manual

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
- [JSON Formats](protocols/json/index.md)
120120
- [Hash](protocols/json/hash.md)
121121
- [Content Address](protocols/json/content-address.md)
122+
- [Store Path](protocols/json/store-path.md)
122123
- [Store Object Info](protocols/json/store-object-info.md)
123124
- [Derivation](protocols/json/derivation.md)
124125
- [Deriving Path](protocols/json/deriving-path.md)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ json_schema_config = files('json-schema-for-humans-config.yaml')
1111
schemas = [
1212
'hash-v1',
1313
'content-address-v1',
14+
'store-path-v1',
1415
'derivation-v3',
1516
'deriving-path-v1',
1617
]

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ properties:
8585
> ]
8686
> ```
8787
items:
88-
type: string
88+
$ref: "store-path-v1.yaml"
8989

9090
inputDrvs:
9191
type: object
@@ -103,6 +103,15 @@ properties:
103103
> ```
104104
>
105105
> 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
109+
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"
114+
additionalProperties: false
106115

107116
system:
108117
type: string
@@ -148,7 +157,7 @@ properties:
148157
type: object
149158
properties:
150159
path:
151-
type: string
160+
$ref: "store-path-v1.yaml"
152161
title: Output path
153162
description: |
154163
The output path, if known in advance.
@@ -167,3 +176,28 @@ properties:
167176
title: Expected hash value
168177
description: |
169178
For fixed-output derivations, the expected content hash in base-16.
179+
180+
outputName:
181+
type: string
182+
title: Output name
183+
description: Name of the derivation output to depend on
184+
185+
outputNames:
186+
type: array
187+
title: Output Names
188+
description: Set of names of derivation outputs to depend on
189+
items:
190+
"$ref": "#/$defs/outputName"
191+
192+
dynamicOutputs:
193+
type: object
194+
title: Dynamic Outputs
195+
description: |
196+
**Experimental feature**: [`dynamic-derivations`](@docroot@/development/experimental-features.md#xp-feature-dynamic-derivations)
197+
198+
This recursive data type allows for depending on outputs of outputs.
199+
properties:
200+
outputs:
201+
"$ref": "#/$defs/outputNames"
202+
dynamicOutputs:
203+
"$ref": "#/$defs/dynamicOutputs"

doc/manual/source/protocols/json/schema/deriving-path-v1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ oneOf:
77
- title: Constant
88
description: |
99
See [Constant](@docroot@/store/derivation/index.md#deriving-path-constant) deriving path.
10-
type: string
10+
$ref: "store-path-v1.yaml"
1111
- title: Output
1212
description: |
1313
See [Output](@docroot@/store/derivation/index.md#deriving-path-output) deriving path.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libstore-tests/data/store-path
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"$schema": "http://json-schema.org/draft-07/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/store-path-v1.json"
3+
title: Store Path
4+
description: |
5+
A [store path](@docroot@/store/store-path.md) identifying a store object.
6+
7+
This schema describes the JSON representation of store paths as used in various Nix JSON APIs.
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+
## Format
16+
17+
Store paths in JSON are represented as strings containing just the hash and name portion, without the store directory prefix.
18+
19+
For example: `"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"`
20+
21+
(If the store dir is `/nix/store`, then this corresponds to the path `/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv`.)
22+
23+
## Structure
24+
25+
The format follows this pattern: `${digest}-${name}`
26+
27+
- **hash**: Digest rendered in a custom variant of [Base32](https://en.wikipedia.org/wiki/Base32) (20 arbitrary bytes become 32 ASCII characters)
28+
- **name**: The package name and optional version/suffix information
29+
30+
type: string
31+
pattern: "^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+$"
32+
minLength: 34
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{#include store-path-v1-fixed.md}}
2+
3+
## Examples
4+
5+
### Simple store path
6+
7+
```json
8+
{{#include schema/store-path-v1/simple.json}}
9+
```
10+
11+
<!--
12+
## Raw Schema
13+
14+
[JSON Schema for Store Path v1](schema/store-path-v1.json)
15+
-->

src/json-schema-checks/meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ schemas = [
3838
'nar.json',
3939
],
4040
},
41+
{
42+
'stem' : 'store-path',
43+
'schema' : schema_dir / 'store-path-v1.yaml',
44+
'files' : [
45+
'simple.json',
46+
],
47+
},
4148
{
4249
'stem' : 'derivation',
4350
'schema' : schema_dir / 'derivation-v3.yaml',

src/json-schema-checks/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mkMesonDerivation (finalAttrs: {
2222
../../doc/manual/source/protocols/json/schema
2323
../../src/libutil-tests/data/hash
2424
../../src/libstore-tests/data/content-address
25+
../../src/libstore-tests/data/store-path
2526
../../src/libstore-tests/data/derivation
2627
../../src/libstore-tests/data/derived-path
2728
./.

0 commit comments

Comments
 (0)