Skip to content

Commit 6ca3434

Browse files
authored
Merge pull request #14309 from obsidiansystems/json-schema-content-address
` nlohmann::json` instance and JSON Schema for `ContentAddress`
2 parents 8e6b69d + 91b69e9 commit 6ca3434

File tree

18 files changed

+242
-37
lines changed

18 files changed

+242
-37
lines changed

doc/manual/package.nix

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

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
- [Formats and Protocols](protocols/index.md)
119119
- [JSON Formats](protocols/json/index.md)
120120
- [Hash](protocols/json/hash.md)
121+
- [Content Address](protocols/json/content-address.md)
121122
- [Store Object Info](protocols/json/store-object-info.md)
122123
- [Derivation](protocols/json/derivation.md)
123124
- [Deriving Path](protocols/json/deriving-path.md)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{#include content-address-v1-fixed.md}}
2+
3+
## Examples
4+
5+
### [Text](@docroot@/store/store-object/content-address.html#method-text) method
6+
7+
```json
8+
{{#include schema/content-address-v1/text.json}}
9+
```
10+
11+
### [Nix Archive](@docroot@/store/store-object/content-address.html#method-nix-archive) method
12+
13+
```json
14+
{{#include schema/content-address-v1/nar.json}}
15+
```
16+
17+
<!-- need to convert YAML to JSON first
18+
## Raw Schema
19+
20+
[JSON Schema for Hash v1](schema/content-address-v1.json)
21+
-->

doc/manual/source/protocols/json/fixup-json-schema-generated-doc.sed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ s/\\`/`/g
1212
# As we have more such relative links, more replacements of this nature
1313
# should appear below.
1414
s^\(./hash-v1.yaml\)\?#/$defs/algorithm^[JSON format for `Hash`](./hash.html#algorithm)^g
15+
s^\(./hash-v1.yaml\)^[JSON format for `Hash`](./hash.html)^g
16+
s^\(./content-address-v1.yaml\)\?#/$defs/method^[JSON format for `ContentAddress`](./content-address.html#method)^g
17+
s^\(./content-address-v1.yaml\)^[JSON format for `ContentAddress`](./content-address.html)^g

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ json_schema_config = files('json-schema-for-humans-config.yaml')
1010

1111
schemas = [
1212
'hash-v1',
13+
'content-address-v1',
1314
'derivation-v3',
1415
'deriving-path-v1',
1516
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libstore-tests/data/content-address
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/content-address-v1.json"
3+
title: Content Address
4+
description: |
5+
This schema describes the JSON representation of Nix's `ContentAddress` type, which conveys information about [content-addressing store objects](@docroot@/store/store-object/content-address.md).
6+
7+
> **Note**
8+
>
9+
> For current methods of content addressing, this data type is a bit suspicious, because it is neither simply a content address of a file system object (the `method` is richer), nor simply a content address of a store object (the `hash` doesn't account for the references).
10+
> It should thus only be used in contexts where the references are also known / otherwise made tamper-resistant.
11+
12+
<!--
13+
TODO currently `ContentAddress` is used in both of these, and so same rationale applies, but actually in both cases the JSON is currently ad-hoc.
14+
That will be fixed, and as each is fixed, the example (along with a more precise link to the field in question) should be become part of the above note, so what is is saying is more clear.
15+
16+
> For example:
17+
18+
> - Fixed outputs of derivations are not allowed to have any references, so an empty reference set is statically known by assumption.
19+
20+
> - [Store object info](./store-object-info.md) includes the set of references along side the (optional) content address.
21+
22+
> This data type is thus safely used in both of these contexts.
23+
24+
-->
25+
26+
type: object
27+
properties:
28+
method:
29+
"$ref": "#/$defs/method"
30+
hash:
31+
title: Content Address
32+
description: |
33+
This would be the content-address itself.
34+
35+
For all current methods, this is just a content address of the file system object of the store object, [as described in the store chapter](@docroot@/store/file-system-object/content-address.md), and not of the store object as a whole.
36+
In particular, the references of the store object are *not* taken into account with this hash (and currently-supported methods).
37+
"$ref": "./hash-v1.yaml"
38+
required:
39+
- method
40+
- hash
41+
additionalProperties: false
42+
"$defs":
43+
method:
44+
type: string
45+
enum: [flat, nar, text, git]
46+
title: Content-Addressing Method
47+
description: |
48+
A string representing the [method](@docroot@/store/store-object/content-address.md) of content addressing that is chosen.
49+
50+
Valid method strings are:
51+
52+
- [`flat`](@docroot@/store/store-object/content-address.md#method-flat) (provided the contents are a single file)
53+
- [`nar`](@docroot@/store/store-object/content-address.md#method-nix-archive)
54+
- [`text`](@docroot@/store/store-object/content-address.md#method-text)
55+
- [`git`](@docroot@/store/store-object/content-address.md#method-git)

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"$schema": http://json-schema.org/draft-04/schema#
2-
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json"
33
title: Derivation
44
description: |
55
Experimental JSON representation of a Nix derivation (version 3).
@@ -154,19 +154,10 @@ properties:
154154
The output path, if known in advance.
155155
156156
method:
157-
type: string
158-
title: Content addressing method
159-
enum: [flat, nar, text, git]
157+
"$ref": "./content-address-v1.yaml#/$defs/method"
160158
description: |
161159
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.
162-
163-
Valid method strings are:
164-
165-
- [`flat`](@docroot@/store/store-object/content-address.md#method-flat)
166-
- [`nar`](@docroot@/store/store-object/content-address.md#method-nix-archive)
167-
- [`text`](@docroot@/store/store-object/content-address.md#method-text)
168-
- [`git`](@docroot@/store/store-object/content-address.md#method-git)
169-
160+
See the linked original definition for further details.
170161
hashAlgo:
171162
title: Hash algorithm
172163
"$ref": "./hash-v1.yaml#/$defs/algorithm"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"$schema": http://json-schema.org/draft-04/schema#
2-
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/deriving-path-v1.json
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/deriving-path-v1.json"
33
title: Deriving Path
44
description: |
55
This schema describes the JSON representation of Nix's [Deriving Path](@docroot@/store/derivation/index.md#deriving-path).

doc/manual/source/protocols/json/schema/hash-v1.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"$schema": http://json-schema.org/draft-04/schema#
2-
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/hash-v1.json
1+
"$schema": "http://json-schema.org/draft-04/schema"
2+
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/hash-v1.json"
33
title: Hash
44
description: |
55
A cryptographic hash value used throughout Nix for content addressing and integrity verification.

0 commit comments

Comments
 (0)