Skip to content

Commit a835d6a

Browse files
authored
Merge pull request #14319 from obsidiansystems/json-schema-fso
`nlohmann::json` instance and JSON Schema for `MemorySourceAccessor`
2 parents ec3c93f + 7357a65 commit a835d6a

File tree

26 files changed

+605
-101
lines changed

26 files changed

+605
-101
lines changed

doc/manual/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mkMesonDerivation (finalAttrs: {
3737
(fileset.unions [
3838
../../.version
3939
# For example JSON
40+
../../src/libutil-tests/data/memory-source-accessor
4041
../../src/libutil-tests/data/hash
4142
../../src/libstore-tests/data/content-address
4243
../../src/libstore-tests/data/store-path

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
- [Architecture and Design](architecture/architecture.md)
122122
- [Formats and Protocols](protocols/index.md)
123123
- [JSON Formats](protocols/json/index.md)
124+
- [File System Object](protocols/json/file-system-object.md)
124125
- [Hash](protocols/json/hash.md)
125126
- [Content Address](protocols/json/content-address.md)
126127
- [Store Path](protocols/json/store-path.md)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{#include file-system-object-v1-fixed.md}}
2+
3+
## Examples
4+
5+
### Simple
6+
7+
```json
8+
{{#include schema/file-system-object-v1/simple.json}}
9+
```
10+
11+
### Complex
12+
13+
```json
14+
{{#include schema/file-system-object-v1/complex.json}}
15+
```
16+
17+
<!-- need to convert YAML to JSON first
18+
## Raw Schema
19+
20+
[JSON Schema for File System Object v1](schema/file-system-object-v1.json)
21+
-->

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ s/\\`/`/g
1111
#
1212
# As we have more such relative links, more replacements of this nature
1313
# should appear below.
14+
s^#/\$defs/\(regular\|symlink\|directory\)^In this schema^g
1415
s^\(./hash-v1.yaml\)\?#/$defs/algorithm^[JSON format for `Hash`](./hash.html#algorithm)^g
1516
s^\(./hash-v1.yaml\)^[JSON format for `Hash`](./hash.html)^g
1617
s^\(./content-address-v1.yaml\)\?#/$defs/method^[JSON format for `ContentAddress`](./content-address.html#method)^g

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ json_schema_for_humans = find_program('generate-schema-doc', required : false)
99
json_schema_config = files('json-schema-for-humans-config.yaml')
1010

1111
schemas = [
12+
'file-system-object-v1',
1213
'hash-v1',
1314
'content-address-v1',
1415
'store-path-v1',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../src/libutil-tests/data/memory-source-accessor
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"$schema": http://json-schema.org/draft-04/schema#
2+
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/file-system-object-v1.json
3+
title: File System Object
4+
description: |
5+
This schema describes the JSON representation of Nix's [File System Object](@docroot@/store/file-system-object.md).
6+
7+
The schema is recursive because file system objects contain other file system objects.
8+
type: object
9+
required: ["type"]
10+
properties:
11+
type:
12+
type: string
13+
enum: ["regular", "symlink", "directory"]
14+
15+
# Enforce conditional structure based on `type`
16+
anyOf:
17+
- $ref: "#/$defs/regular"
18+
required: ["type", "contents"]
19+
20+
- $ref: "#/$defs/directory"
21+
required: ["type", "entries"]
22+
23+
- $ref: "#/$defs/symlink"
24+
required: ["type", "target"]
25+
26+
"$defs":
27+
regular:
28+
title: Regular File
29+
description: |
30+
See [Regular File](@docroot@/store/file-system-object.md#regular) in the manual for details.
31+
required: ["contents"]
32+
properties:
33+
type:
34+
const: "regular"
35+
contents:
36+
type: string
37+
description: File contents
38+
executable:
39+
type: boolean
40+
description: Whether the file is executable.
41+
default: false
42+
additionalProperties: false
43+
44+
directory:
45+
title: Directory
46+
description: |
47+
See [Directory](@docroot@/store/file-system-object.md#directory) in the manual for details.
48+
required: ["entries"]
49+
properties:
50+
type:
51+
const: "directory"
52+
entries:
53+
type: object
54+
description: |
55+
Map of names to nested file system objects (for type=directory)
56+
additionalProperties:
57+
$ref: "#"
58+
additionalProperties: false
59+
60+
symlink:
61+
title: Symbolic Link
62+
description: |
63+
See [Symbolic Link](@docroot@/store/file-system-object.md#symlink) in the manual for details.
64+
required: ["target"]
65+
properties:
66+
type:
67+
const: "symlink"
68+
target:
69+
type: string
70+
description: Target path of the symlink.
71+
additionalProperties: false

doc/manual/source/store/file-system-object.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
Nix uses a simplified model of the file system, which consists of file system objects.
44
Every file system object is one of the following:
55

6-
- File
6+
- [**Regular File**]{#regular}
77

88
- A possibly empty sequence of bytes for contents
99
- A single boolean representing the [executable](https://en.m.wikipedia.org/wiki/File-system_permissions#Permissions) permission
1010

11-
- Directory
11+
- [**Directory**]{#directory}
1212

1313
Mapping of names to child file system objects
1414

15-
- [Symbolic link](https://en.m.wikipedia.org/wiki/Symbolic_link)
15+
- [**Symbolic link**]{#symlink}
1616

17-
An arbitrary string.
18-
Nix does not assign any semantics to symbolic links.
17+
An arbitrary string, known as the *target* of the symlink.
18+
19+
In general, Nix does not assign any semantics to symbolic links.
20+
Certain operations however, may make additional assumptions and attempt to use the target to find another file system object.
21+
22+
> See [the Wikpedia article on symbolic links](https://en.m.wikipedia.org/wiki/Symbolic_link) for background information if you are unfamiliar with this Unix concept.
1923
2024
File system objects and their children form a tree.
2125
A bare file or symlink can be a root file system object.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../src/libutil-tests/data/memory-source-accessor

src/json-schema-checks/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ schema_dir = meson.current_source_dir() / 'schema'
2020

2121
# Get all example files
2222
schemas = [
23+
{
24+
'stem' : 'file-system-object',
25+
'schema' : schema_dir / 'file-system-object-v1.yaml',
26+
'files' : [
27+
'simple.json',
28+
'complex.json',
29+
],
30+
},
2331
{
2432
'stem' : 'hash',
2533
'schema' : schema_dir / 'hash-v1.yaml',

0 commit comments

Comments
 (0)