Skip to content

Commit b4fcb64

Browse files
authored
Merge pull request #13980 from obsidiansystems/drv-json-issue-13570
Make the JSON format for derivation use basename store paths
2 parents 82315c3 + 9d7229a commit b4fcb64

31 files changed

+275
-140
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
synopsis: Derivation JSON format now uses store path basenames (no store dir) only
3+
prs: [13980]
4+
issues: [13570]
5+
---
6+
7+
Experience with many JSON frameworks (e.g. nlohmann/json in C++, Serde
8+
in Rust, and Aeson in Haskell), has show that the use of the store dir
9+
in JSON formats is an impediment to systematic JSON formats, because it
10+
requires the serializer/deserializer to take an extra paramater (the
11+
store dir).
12+
13+
We ultimately want to rectify this issue with all (non-stable, able to
14+
be changed) JSON formats. To start with, we are changing the JSON format
15+
for derivations because the `nix derivation` commands are --- in
16+
addition to being formally unstable --- less widely used than other
17+
unstable commands.

doc/manual/source/protocols/json/derivation.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ is a JSON object with the following fields:
1414
The name of the derivation.
1515
This is used when calculating the store paths of the derivation's outputs.
1616

17+
* `version`:
18+
Must be `3`.
19+
This is a guard that allows us to continue evolving this format.
20+
The choice of `3` is fairly arbitrary, but corresponds to this informal version:
21+
22+
- Version 0: A-Term format
23+
24+
- Version 1: Original JSON format, with ugly `"r:sha256"` inherited from A-Term format.
25+
26+
- Version 2: Separate `method` and `hashAlgo` fields in output specs
27+
28+
- Verison 3: Drop store dir from store paths, just include base name.
29+
30+
Note that while this format is experimental, the maintenance of versions is best-effort, and not promised to identify every change.
31+
1732
* `outputs`:
1833
Information about the output paths of the derivation.
1934
This is a JSON object with one member per output, where the key is the output name and the value is a JSON object with these fields:
@@ -52,7 +67,6 @@ is a JSON object with the following fields:
5267
> ```json
5368
> "outputs": {
5469
> "out": {
55-
> "path": "/nix/store/2543j7c6jn75blc3drf4g5vhb1rhdq29-source",
5670
> "method": "nar",
5771
> "hashAlgo": "sha256",
5872
> "hash": "6fc80dcc62179dbc12fc0b5881275898f93444833d21b89dfe5f7fbcbb1d0d62"
@@ -63,15 +77,24 @@ is a JSON object with the following fields:
6377
* `inputSrcs`:
6478
A list of store paths on which this derivation depends.
6579
80+
> **Example**
81+
>
82+
> ```json
83+
> "inputSrcs": [
84+
> "47y241wqdhac3jm5l7nv0x4975mb1975-separate-debug-info.sh",
85+
> "56d0w71pjj9bdr363ym3wj1zkwyqq97j-fix-pop-var-context-error.patch"
86+
> ]
87+
> ```
88+
6689
* `inputDrvs`:
6790
A JSON object specifying the derivations on which this derivation depends, and what outputs of those derivations.
6891
6992
> **Example**
7093
>
7194
> ```json
7295
> "inputDrvs": {
73-
> "/nix/store/6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
74-
> "/nix/store/fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
96+
> "6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
97+
> "fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
7598
> }
7699
> ```
77100

src/libstore-c/nix_api_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ nix_derivation * nix_derivation_from_json(nix_c_context * context, Store * store
181181
if (context)
182182
context->last_err_code = NIX_OK;
183183
try {
184-
auto drv = nix::Derivation::fromJSON(*store->ptr, nlohmann::json::parse(json));
184+
auto drv = static_cast<nix::Derivation>(nlohmann::json::parse(json));
185185

186186
auto drvPath = nix::writeDerivation(*store->ptr, drv, nix::NoRepair, /* read only */ true);
187187

src/libstore-tests/data/derivation/ca/advanced-attributes-defaults.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
"method": "nar"
2222
}
2323
},
24-
"system": "my-system"
24+
"system": "my-system",
25+
"version": 3
2526
}

src/libstore-tests/data/derivation/ca/advanced-attributes-structured-attrs-defaults.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
],
3333
"system": "my-system"
3434
},
35-
"system": "my-system"
35+
"system": "my-system",
36+
"version": 3
3637
}

src/libstore-tests/data/derivation/ca/advanced-attributes-structured-attrs.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
"out": "/1rz4g4znpzjwh1xymhjpm42vipw92pr73vdgl6xs1hycac8kf2n9"
1111
},
1212
"inputDrvs": {
13-
"/nix/store/j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv": {
13+
"j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv": {
1414
"dynamicOutputs": {},
1515
"outputs": [
1616
"dev",
1717
"out"
1818
]
1919
},
20-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv": {
20+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv": {
2121
"dynamicOutputs": {},
2222
"outputs": [
2323
"dev",
@@ -26,7 +26,7 @@
2626
}
2727
},
2828
"inputSrcs": [
29-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
29+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
3030
],
3131
"name": "advanced-attributes-structured-attrs",
3232
"outputs": {
@@ -100,5 +100,6 @@
100100
],
101101
"system": "my-system"
102102
},
103-
"system": "my-system"
103+
"system": "my-system",
104+
"version": 3
104105
}

src/libstore-tests/data/derivation/ca/advanced-attributes.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"system": "my-system"
2727
},
2828
"inputDrvs": {
29-
"/nix/store/j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv": {
29+
"j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv": {
3030
"dynamicOutputs": {},
3131
"outputs": [
3232
"dev",
3333
"out"
3434
]
3535
},
36-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv": {
36+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv": {
3737
"dynamicOutputs": {},
3838
"outputs": [
3939
"dev",
@@ -42,7 +42,7 @@
4242
}
4343
},
4444
"inputSrcs": [
45-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
45+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
4646
],
4747
"name": "advanced-attributes",
4848
"outputs": {
@@ -51,5 +51,6 @@
5151
"method": "nar"
5252
}
5353
},
54-
"system": "my-system"
54+
"system": "my-system",
55+
"version": 3
5556
}

src/libstore-tests/data/derivation/ca/self-contained.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
"method": "nar"
2020
}
2121
},
22-
"system": "x86_64-linux"
22+
"system": "x86_64-linux",
23+
"version": 3
2324
}

src/libstore-tests/data/derivation/dynDerivationDeps.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"BIG_BAD": "WOLF"
99
},
1010
"inputDrvs": {
11-
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv": {
11+
"c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv": {
1212
"dynamicOutputs": {
1313
"cat": {
1414
"dynamicOutputs": {},
@@ -30,9 +30,10 @@
3030
}
3131
},
3232
"inputSrcs": [
33-
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
33+
"c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
3434
],
3535
"name": "dyn-dep-derivation",
3636
"outputs": {},
37-
"system": "wasm-sel4"
37+
"system": "wasm-sel4",
38+
"version": 3
3839
}

src/libstore-tests/data/derivation/ia/advanced-attributes-defaults.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"name": "advanced-attributes-defaults",
1616
"outputs": {
1717
"out": {
18-
"path": "/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults"
18+
"path": "1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults"
1919
}
2020
},
21-
"system": "my-system"
21+
"system": "my-system",
22+
"version": 3
2223
}

0 commit comments

Comments
 (0)