Skip to content

Commit 81921d7

Browse files
Ericson2314xokdvium
andcommitted
Parse deriving paths in DerivationOptions
This is an example of "Parse, don't validate" principle [1]. Before, we had a number of `StringSet`s in `DerivationOptions` that were not *actually* allowed to be arbitrary sets of strings. Instead, each set member had to be one of: - a store path - a CA "downstream placeholder" - an output name Only later, in the code that checks outputs, would these strings be further parsed to match these cases. (Actually, only 2 by that point, because the placeholders must be rewritten away by then.) Now, we fully parse everything up front, and have an "honest" data type that reflects these invariants: - store paths are parsed, stored as (opaque) deriving paths - CA "downstream placeholders" are rewritten to the output deriving paths they denote - output names are the only arbitrary strings left Since the first two cases both become deriving paths, that leaves us with a `std::variant<SingleDerivedPath, String>` data type, which we use in our sets instead. Getting rid of placeholders is especially nice because we are replacing them with something much more internally-structured / transparent. [1]: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ Co-authored-by: Sergei Zimmerman <[email protected]>
1 parent 68a5110 commit 81921d7

22 files changed

+737
-262
lines changed

src/libstore-tests/data/derivation/ca/all_set.json

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"allowSubstitutes": false,
55
"exportReferencesGraph": {
66
"refs1": [
7-
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
7+
{
8+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
9+
"output": "out"
10+
}
811
],
912
"refs2": [
10-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
13+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
1114
]
1215
},
1316
"impureEnvVars": [
@@ -20,18 +23,36 @@
2023
"outputChecks": {
2124
"forAllOutputs": {
2225
"allowedReferences": [
23-
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
26+
{
27+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
28+
"output": "out"
29+
}
2430
],
2531
"allowedRequisites": [
26-
"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z",
27-
"bin"
32+
{
33+
"drvPath": "self",
34+
"output": "bin"
35+
},
36+
{
37+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
38+
"output": "dev"
39+
}
2840
],
2941
"disallowedReferences": [
30-
"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g",
31-
"dev"
42+
{
43+
"drvPath": "self",
44+
"output": "dev"
45+
},
46+
{
47+
"drvPath": "qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
48+
"output": "out"
49+
}
3250
],
3351
"disallowedRequisites": [
34-
"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"
52+
{
53+
"drvPath": "qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
54+
"output": "dev"
55+
}
3556
],
3657
"ignoreSelfRefs": true,
3758
"maxClosureSize": null,

src/libstore-tests/data/derivation/ca/structuredAttrs_all_set.json

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"allowSubstitutes": false,
55
"exportReferencesGraph": {
66
"refs1": [
7-
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
7+
{
8+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
9+
"output": "out"
10+
}
811
],
912
"refs2": [
10-
"/nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
13+
"qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv"
1114
]
1215
},
1316
"impureEnvVars": [
@@ -23,11 +26,20 @@
2326
"allowedReferences": null,
2427
"allowedRequisites": null,
2528
"disallowedReferences": [
26-
"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g",
27-
"dev"
29+
{
30+
"drvPath": "self",
31+
"output": "dev"
32+
},
33+
{
34+
"drvPath": "qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
35+
"output": "out"
36+
}
2837
],
2938
"disallowedRequisites": [
30-
"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"
39+
{
40+
"drvPath": "qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
41+
"output": "dev"
42+
}
3143
],
3244
"ignoreSelfRefs": false,
3345
"maxClosureSize": null,
@@ -44,11 +56,20 @@
4456
},
4557
"out": {
4658
"allowedReferences": [
47-
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
59+
{
60+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
61+
"output": "out"
62+
}
4863
],
4964
"allowedRequisites": [
50-
"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z",
51-
"bin"
65+
{
66+
"drvPath": "self",
67+
"output": "bin"
68+
},
69+
{
70+
"drvPath": "j56sf12rxpcv5swr14vsjn5cwm6bj03h-foo.drv",
71+
"output": "dev"
72+
}
5273
],
5374
"disallowedReferences": [],
5475
"disallowedRequisites": [],

src/libstore-tests/data/derivation/ia/all_set.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"allowSubstitutes": false,
55
"exportReferencesGraph": {
66
"refs1": [
7-
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
7+
"p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
88
],
99
"refs2": [
10-
"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"
10+
"vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"
1111
]
1212
},
1313
"impureEnvVars": [
@@ -20,18 +20,24 @@
2020
"outputChecks": {
2121
"forAllOutputs": {
2222
"allowedReferences": [
23-
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
23+
"p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
2424
],
2525
"allowedRequisites": [
26-
"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev",
27-
"bin"
26+
{
27+
"drvPath": "self",
28+
"output": "bin"
29+
},
30+
"z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"
2831
],
2932
"disallowedReferences": [
30-
"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar",
31-
"dev"
33+
{
34+
"drvPath": "self",
35+
"output": "dev"
36+
},
37+
"r5cff30838majxk5mp3ip2diffi8vpaj-bar"
3238
],
3339
"disallowedRequisites": [
34-
"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
40+
"9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
3541
],
3642
"ignoreSelfRefs": true,
3743
"maxClosureSize": null,

src/libstore-tests/data/derivation/ia/structuredAttrs_all_set.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"allowSubstitutes": false,
55
"exportReferencesGraph": {
66
"refs1": [
7-
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
7+
"p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
88
],
99
"refs2": [
10-
"/nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"
10+
"vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv"
1111
]
1212
},
1313
"impureEnvVars": [
@@ -23,11 +23,14 @@
2323
"allowedReferences": null,
2424
"allowedRequisites": null,
2525
"disallowedReferences": [
26-
"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar",
27-
"dev"
26+
{
27+
"drvPath": "self",
28+
"output": "dev"
29+
},
30+
"r5cff30838majxk5mp3ip2diffi8vpaj-bar"
2831
],
2932
"disallowedRequisites": [
30-
"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
33+
"9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
3134
],
3235
"ignoreSelfRefs": false,
3336
"maxClosureSize": null,
@@ -44,11 +47,14 @@
4447
},
4548
"out": {
4649
"allowedReferences": [
47-
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
50+
"p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
4851
],
4952
"allowedRequisites": [
50-
"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev",
51-
"bin"
53+
{
54+
"drvPath": "self",
55+
"output": "bin"
56+
},
57+
"z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"
5258
],
5359
"disallowedReferences": [],
5460
"disallowedRequisites": [],

0 commit comments

Comments
 (0)