Skip to content

Commit 100e7cc

Browse files
committed
Reapply "Use the hash modulo in the derivation outputs"
This reverts commit 4f91e95. This broke: when I applied this pr, `--print-out-paths` wouldn't print anything: ``` shell-for-nix-env % nix build --print-out-paths .#legacyPackages.aarch64-darwin.homeConfigurations.macos.activationPackage ``` After dropping the patches from my fork, it does again. ``` shell-for-nix-env % nix build --print-out-paths .#legacyPackages.aarch64-darwin.homeConfigurations.macos.activationPackage /nix/store/s8mlcalszdml0v8172w4hwqnx0m6477r-home-manager-generation ```
1 parent a98b43b commit 100e7cc

72 files changed

Lines changed: 879 additions & 1150 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/manual/source/protocols/json/schema/build-result-v1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ properties:
8383
description: |
8484
A mapping from output names to their build trace entries.
8585
additionalProperties:
86-
"$ref": "build-trace-entry-v2.yaml#/$defs/value"
86+
"$ref": "build-trace-entry-v2.yaml"
8787

8888
failure:
8989
type: object

doc/manual/source/protocols/json/schema/build-trace-entry-v2.yaml

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ description: |
1616
1717
- Version 1: Original format
1818
19-
- Version 2:
20-
- Use `drvPath` not `drvHash` to refer to derivation in a more conventional way.
21-
- Remove `dependentRealisations`
22-
- Separate into `key` and `value`
19+
- Version 2: Remove `dependentRealisations`
2320
2421
type: object
2522
required:
26-
- key
27-
- value
23+
- id
24+
- outPath
25+
- signatures
26+
allOf:
27+
- "$ref": "#/$defs/key"
28+
- "$ref": "#/$defs/value"
2829
properties:
29-
key:
30-
"$ref": "#/$defs/key"
31-
value:
32-
"$ref": "#/$defs/value"
33-
additionalProperties: false
30+
id: {}
31+
outPath: {}
32+
signatures: {}
33+
additionalProperties:
34+
dependentRealisations:
35+
description: deprecated field
36+
type: object
3437

3538
"$defs":
3639
key:
@@ -40,20 +43,23 @@ additionalProperties: false
4043
This is the "key" part, refering to a derivation and output.
4144
type: object
4245
required:
43-
- drvPath
44-
- outputName
46+
- id
4547
properties:
46-
drvPath:
47-
"$ref": "store-path-v1.yaml"
48-
title: Derivation Path
49-
description: |
50-
The store path of the derivation that was built.
51-
outputName:
48+
id:
5249
type: string
53-
title: Output Name
50+
title: Derivation Output ID
51+
pattern: "^sha256:[0-9a-f]{64}![a-zA-Z_][a-zA-Z0-9_-]*$"
5452
description: |
55-
Name of the specific output (e.g., "out", "dev", "doc")
56-
additionalProperties: false
53+
Unique identifier for the derivation output that was built.
54+
55+
Format: `{hash-quotient-drv}!{output-name}`
56+
57+
- **hash-quotient-drv**: SHA-256 [hash of the quotient derivation](@docroot@/store/derivation/outputs/input-address.md#hash-quotient-drv).
58+
Begins with `sha256:`.
59+
60+
- **output-name**: Name of the specific output (e.g., "out", "dev", "doc")
61+
62+
Example: `"sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad!foo"`
5763
5864
value:
5965
title: Build Trace Value
@@ -71,6 +77,13 @@ additionalProperties: false
7177
description: |
7278
The path to the store object that resulted from building this derivation for the given output name.
7379
80+
patternProperties:
81+
"^sha256:[0-9a-f]{64}![a-zA-Z_][a-zA-Z0-9_-]*$":
82+
"$ref": "store-path-v1.yaml"
83+
title: Dependent Store Path
84+
description: Store path that this dependency resolved to during the build
85+
additionalProperties: false
86+
7487
signatures:
7588
type: array
7689
title: Build Signatures

src/json-schema-checks/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ schemas = [
6565
'schema' : schema_dir / 'build-trace-entry-v2.yaml',
6666
'files' : [
6767
'simple.json',
68+
# The field is no longer supported, but we want to show that we
69+
# ignore it during parsing.
70+
'with-dependent-realisations.json',
6871
'with-signature.json',
6972
],
7073
},

src/libcmd/built-path.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,20 @@ RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
108108
overloaded{
109109
[&](const BuiltPath::Opaque & p) { res.insert(p.path); },
110110
[&](const BuiltPath::Built & p) {
111+
auto drvHashes = staticOutputHashes(store, store.readDerivation(p.drvPath->outPath()));
111112
for (auto & [outputName, outputPath] : p.outputs) {
112113
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
113-
DrvOutput key{
114-
.drvPath = p.drvPath->outPath(),
115-
.outputName = outputName,
116-
};
114+
auto drvOutput = get(drvHashes, outputName);
115+
if (!drvOutput)
116+
throw Error(
117+
"the derivation '%s' has unrealised output '%s' (derived-path.cc/toRealisedPaths)",
118+
store.printStorePath(p.drvPath->outPath()),
119+
outputName);
120+
DrvOutput key{*drvOutput, outputName};
117121
auto thisRealisation = store.queryRealisation(key);
118-
// We’ve built it, so we must have the realisation.
119-
assert(thisRealisation);
120-
res.insert(Realisation{*thisRealisation, key});
122+
assert(thisRealisation); // We’ve built it, so we must
123+
// have the realisation
124+
res.insert(Realisation{*thisRealisation, std::move(key)});
121125
} else {
122126
res.insert(outputPath);
123127
}

src/libstore-tests/build-result.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,25 @@ INSTANTIATE_TEST_SUITE_P(
7575
{
7676
"foo",
7777
{
78-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
78+
{
79+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
80+
},
81+
DrvOutput{
82+
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
83+
.outputName = "foo",
84+
},
7985
},
8086
},
8187
{
8288
"bar",
8389
{
84-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar"},
90+
{
91+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar"},
92+
},
93+
DrvOutput{
94+
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
95+
.outputName = "bar",
96+
},
8597
},
8698
},
8799
},

src/libstore-tests/common-protocol.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,69 @@ CHARACTERIZATION_TEST(
108108
},
109109
}))
110110

111+
CHARACTERIZATION_TEST(
112+
drvOutput,
113+
"drv-output",
114+
(std::tuple<DrvOutput, DrvOutput>{
115+
{
116+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
117+
.outputName = "baz",
118+
},
119+
DrvOutput{
120+
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
121+
.outputName = "quux",
122+
},
123+
}))
124+
125+
CHARACTERIZATION_TEST(
126+
realisation,
127+
"realisation",
128+
(std::tuple<Realisation, Realisation>{
129+
Realisation{
130+
{
131+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
132+
},
133+
{
134+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
135+
.outputName = "baz",
136+
},
137+
},
138+
Realisation{
139+
{
140+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
141+
.signatures =
142+
{
143+
Signature{.keyName = "asdf", .sig = std::string(64, '\0')},
144+
Signature{.keyName = "qwer", .sig = std::string(64, '\0')},
145+
},
146+
},
147+
{
148+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
149+
.outputName = "baz",
150+
},
151+
},
152+
}))
153+
154+
READ_CHARACTERIZATION_TEST(
155+
realisation_with_deps,
156+
"realisation-with-deps",
157+
(std::tuple<Realisation>{
158+
Realisation{
159+
{
160+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
161+
.signatures =
162+
{
163+
Signature{.keyName = "asdf", .sig = std::string(64, '\0')},
164+
Signature{.keyName = "qwer", .sig = std::string(64, '\0')},
165+
},
166+
},
167+
{
168+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
169+
.outputName = "baz",
170+
},
171+
},
172+
}))
173+
111174
CHARACTERIZATION_TEST(
112175
vector,
113176
"vector",

src/libstore-tests/data/build-result/success.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"builtOutputs": {
33
"bar": {
4+
"dependentRealisations": {},
5+
"id": "sha256:6f869f9ea2823bda165e06076fd0de4366dead2c0e8d2dbbad277d4f15c373f5!bar",
46
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
57
"signatures": []
68
},
79
"foo": {
10+
"dependentRealisations": {},
11+
"id": "sha256:6f869f9ea2823bda165e06076fd0de4366dead2c0e8d2dbbad277d4f15c373f5!foo",
812
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
913
"signatures": []
1014
}

src/libstore-tests/data/dummy-store/one-realisation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"buildTrace": {
3-
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv": {
3+
"ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=": {
44
"out": {
5+
"dependentRealisations": {},
56
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
67
"signatures": []
78
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"key": {
3-
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
4-
"outputName": "foo"
5-
},
6-
"value": {
7-
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
8-
"signatures": []
9-
}
2+
"dependentRealisations": {},
3+
"id": "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad!foo",
4+
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
5+
"signatures": []
106
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dependentRealisations": {
3+
"sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad!foo": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"
4+
},
5+
"id": "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad!foo",
6+
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
7+
"signatures": []
8+
}

0 commit comments

Comments
 (0)