Skip to content

Commit c679664

Browse files
committed
Create JSON Schema for Store Paths
We immediately use this in the JSON schemas for Derivation and Deriving Path, but we cannot yet use it in Store Object Info because those paths *do* include the store dir currently.
1 parent be2572e commit c679664

File tree

11 files changed

+72
-10
lines changed

11 files changed

+72
-10
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: 11 additions & 9 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,13 +103,15 @@ properties:
103103
> ```
104104
>
105105
> specifies that this derivation depends on the `dev` output of `curl`, and the `out` output of `unzip`.
106-
additionalProperties:
107-
title: Store Path
108-
description: |
109-
A store path to a derivation, mapped to the outputs of that derivation.
110-
oneOf:
111-
- "$ref": "#/$defs/outputNames"
112-
- "$ref": "#/$defs/dynamicOutputs"
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
113115

114116
system:
115117
type: string
@@ -155,7 +157,7 @@ properties:
155157
type: object
156158
properties:
157159
path:
158-
type: string
160+
$ref: "store-path-v1.yaml"
159161
title: Output path
160162
description: |
161163
The output path, if known in advance.

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)