Skip to content

Commit 68a5110

Browse files
authored
Merge pull request #14502 from obsidiansystems/more-store-object-info-json-cleanup
More store object info json cleanup
2 parents 060a354 + 4f1c8f6 commit 68a5110

File tree

18 files changed

+111
-78
lines changed

18 files changed

+111
-78
lines changed

doc/manual/rl-next/json-format-changes.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ The store path info JSON format has been updated from version 1 to version 2:
2222
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
2323
- Still `null` values for input-addressed store objects
2424

25-
Version 1 format is still accepted when reading for backward compatibility.
25+
- **Structured hash fields**:
26+
27+
Hash values (`narHash` and `downloadHash`) are now structured JSON objects instead of strings:
28+
29+
- Old: `"narHash": "sha256:FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="`
30+
- New: `"narHash": {"algorithm": "sha256", "format": "base64", "hash": "FePFYIlM..."}`
31+
- Same structure applies to `downloadHash` in NAR info contexts
32+
33+
Nix currently only produces, and doesn't consume this format.
2634

2735
**Affected command**: `nix path-info --json`
2836

doc/manual/source/protocols/json/schema/store-object-info-v2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $defs:
7171
Note: This field may not be present in all contexts, such as when the path is used as the key and the the store object info the value in map.
7272
7373
narHash:
74-
type: string
74+
"$ref": "./hash-v1.yaml"
7575
title: NAR Hash
7676
description: |
7777
Hash of the [file system object](@docroot@/store/file-system-object.md) part of the store object when serialized as a [Nix Archive](@docroot@/store/file-system-object/content-address.md#serial-nix-archive).
@@ -229,7 +229,7 @@ $defs:
229229
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
230230
231231
downloadHash:
232-
type: string
232+
"$ref": "./hash-v1.yaml"
233233
title: Download Hash
234234
description: |
235235
A digest for the compressed archive itself, as opposed to the data contained within.

src/libstore-tests/data/nar-info/impure.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
},
1010
"compression": "xz",
1111
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
12-
"downloadHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
12+
"downloadHash": {
13+
"algorithm": "sha256",
14+
"format": "base64",
15+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
16+
},
1317
"downloadSize": 4029176,
14-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
18+
"narHash": {
19+
"algorithm": "sha256",
20+
"format": "base64",
21+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
22+
},
1523
"narSize": 34878,
1624
"references": [
1725
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",

src/libstore-tests/data/nar-info/pure.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
},
88
"method": "nar"
99
},
10-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
10+
"narHash": {
11+
"algorithm": "sha256",
12+
"format": "base64",
13+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
14+
},
1115
"narSize": 34878,
1216
"references": [
1317
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",

src/libstore-tests/data/path-info/empty_impure.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"ca": null,
33
"deriver": null,
4-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
4+
"narHash": {
5+
"algorithm": "sha256",
6+
"format": "base64",
7+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
8+
},
59
"narSize": 0,
610
"references": [],
711
"registrationTime": null,

src/libstore-tests/data/path-info/empty_pure.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"ca": null,
3-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
3+
"narHash": {
4+
"algorithm": "sha256",
5+
"format": "base64",
6+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
7+
},
48
"narSize": 0,
59
"references": [],
610
"version": 2

src/libstore-tests/data/path-info/impure.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"method": "nar"
99
},
1010
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
11-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
11+
"narHash": {
12+
"algorithm": "sha256",
13+
"format": "base64",
14+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
15+
},
1216
"narSize": 34878,
1317
"references": [
1418
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",

src/libstore-tests/data/path-info/pure.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
},
88
"method": "nar"
99
},
10-
"narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
10+
"narHash": {
11+
"algorithm": "sha256",
12+
"format": "base64",
13+
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
14+
},
1115
"narSize": 34878,
1216
"references": [
1317
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",

src/libstore-tests/nar-info.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo)
5959
return info;
6060
}
6161

62-
#define JSON_TEST(STEM, PURE) \
63-
TEST_F(NarInfoTest, NarInfo_##STEM##_from_json) \
64-
{ \
65-
readTest(#STEM, [&](const auto & encoded_) { \
66-
auto encoded = json::parse(encoded_); \
67-
auto expected = makeNarInfo(*store, PURE); \
68-
NarInfo got = NarInfo::fromJSON(*store, expected.path, encoded); \
69-
ASSERT_EQ(got, expected); \
70-
}); \
71-
} \
72-
\
73-
TEST_F(NarInfoTest, NarInfo_##STEM##_to_json) \
74-
{ \
75-
writeTest( \
76-
#STEM, \
77-
[&]() -> json { return makeNarInfo(*store, PURE).toJSON(*store, PURE, HashFormat::SRI); }, \
78-
[](const auto & file) { return json::parse(readFile(file)); }, \
79-
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
62+
#define JSON_TEST(STEM, PURE) \
63+
TEST_F(NarInfoTest, NarInfo_##STEM##_from_json) \
64+
{ \
65+
readTest(#STEM, [&](const auto & encoded_) { \
66+
auto encoded = json::parse(encoded_); \
67+
auto expected = makeNarInfo(*store, PURE); \
68+
NarInfo got = NarInfo::fromJSON(*store, expected.path, encoded); \
69+
ASSERT_EQ(got, expected); \
70+
}); \
71+
} \
72+
\
73+
TEST_F(NarInfoTest, NarInfo_##STEM##_to_json) \
74+
{ \
75+
writeTest( \
76+
#STEM, \
77+
[&]() -> json { return makeNarInfo(*store, PURE).toJSON(*store, PURE); }, \
78+
[](const auto & file) { return json::parse(readFile(file)); }, \
79+
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
8080
}
8181

8282
JSON_TEST(pure, false)

src/libstore-tests/path-info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static UnkeyedValidPathInfo makeFull(const Store & store, bool includeImpureInfo
8080
{ \
8181
writeTest( \
8282
#STEM, \
83-
[&]() -> json { return OBJ.toJSON(*store, PURE, HashFormat::SRI); }, \
83+
[&]() -> json { return OBJ.toJSON(*store, PURE); }, \
8484
[](const auto & file) { return json::parse(readFile(file)); }, \
8585
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
8686
}

0 commit comments

Comments
 (0)