Skip to content

Commit d4809b4

Browse files
committed
include options in JSON drv format
1 parent 164b8c7 commit d4809b4

7 files changed

Lines changed: 120 additions & 0 deletions

File tree

src/libstore/derivations.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "derivations.hh"
22
#include "downstream-placeholder.hh"
33
#include "error.hh"
4+
#include "json-utils.hh"
45
#include "store-api.hh"
56
#include "globals.hh"
67
#include "types.hh"
@@ -1427,6 +1428,7 @@ nlohmann::json Derivation::toJSON(const StoreDirConfig & store) const
14271428
res["builder"] = builder;
14281429
res["args"] = args;
14291430
res["env"] = env;
1431+
res["options"] = nlohmann::json(options);
14301432

14311433
return res;
14321434
}
@@ -1484,12 +1486,59 @@ Derivation Derivation::fromJSON(
14841486
throw;
14851487
}
14861488

1489+
auto options = valueAt(json, "options");
1490+
14871491
res.platform = getString(valueAt(json, "system"));
14881492
res.builder = getString(valueAt(json, "builder"));
14891493
res.args = getStringList(valueAt(json, "args"));
14901494
res.env = getStringMap(valueAt(json, "env"));
1495+
res.options = options.get<DerivationOptions>();
1496+
1497+
return res;
1498+
}
1499+
1500+
}
1501+
1502+
namespace nlohmann {
1503+
1504+
using namespace nix;
1505+
1506+
DerivationOptions adl_serializer<DerivationOptions>::from_json(const json & json) {
1507+
DerivationOptions res;
1508+
1509+
res.additionalSandboxProfile = getString(valueAt(json, "additionalSandboxProfile"));
1510+
res.noChroot = getBoolean(valueAt(json, "noChroot"));
1511+
res.impureHostDeps = getStringList(valueAt(json, "impureHostDeps"));
1512+
res.impureEnvVars = getStringList(valueAt(json, "impureEnvVars"));
1513+
res.allowLocalNetworking = getBoolean(valueAt(json, "allowLocalNetworking"));
1514+
1515+
res.allowedReferences = optionalValueAt(json, "allowedReferences");
1516+
res.allowedRequisites = optionalValueAt(json, "allowedRequisites");
1517+
res.disallowedReferences = optionalValueAt(json, "disallowedReferences");
1518+
res.disallowedRequisites = optionalValueAt(json, "disallowedRequisites");
1519+
1520+
res.requiredSystemFeatures = getStringList(valueAt(json, "requiredSystemFeatures"));
1521+
res.preferLocalBuild = getBoolean(valueAt(json, "preferLocalBuild"));
1522+
res.allowSubstitutes = getBoolean(valueAt(json, "allowSubstitutes"));
14911523

14921524
return res;
14931525
}
14941526

1527+
void adl_serializer<DerivationOptions>::to_json(json & json, DerivationOptions o) {
1528+
json["additionalSandboxProfile"] = o.additionalSandboxProfile;
1529+
json["noChroot"] = o.noChroot;
1530+
json["impureHostDeps"] = o.impureHostDeps;
1531+
json["impureEnvVars"] = o.impureEnvVars;
1532+
json["allowLocalNetworking"] = o.allowLocalNetworking;
1533+
1534+
json["disallowedReferences"] = o.allowedReferences;
1535+
json["disallowedRequisites"] = o.allowedRequisites;
1536+
json["disallowedReferences"] = o.disallowedReferences;
1537+
json["disallowedRequisites"] = o.disallowedRequisites;
1538+
1539+
json["requiredSystemFeatures"] = o.requiredSystemFeatures;
1540+
json["preferLocalBuild"] = o.preferLocalBuild;
1541+
json["allowSubstitutes"] = o.allowSubstitutes;
1542+
}
1543+
14951544
}

src/libstore/derivations.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
///@file
33

4+
#include "json-impls.hh"
45
#include "path.hh"
56
#include "types.hh"
67
#include "hash.hh"
@@ -10,6 +11,7 @@
1011
#include "sync.hh"
1112
#include "comparator.hh"
1213
#include "variant-wrapper.hh"
14+
#include <nlohmann/json.hpp>
1315

1416
#include <map>
1517
#include <optional>
@@ -630,3 +632,5 @@ std::string hashPlaceholder(const OutputNameView outputName);
630632
extern const Hash impureOutputHash;
631633

632634
}
635+
636+
JSON_IMPL(DerivationOptions)

tests/unit/libstore/data/derivation/advanced-attributes-defaults.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
"inputDrvs": {},
1414
"inputSrcs": [],
1515
"name": "advanced-attributes-defaults",
16+
"options": {
17+
"additionalSandboxProfile": "",
18+
"allowLocalNetworking": false,
19+
"allowSubstitutes": true,
20+
"disallowedReferences": null,
21+
"disallowedRequisites": null,
22+
"impureEnvVars": [],
23+
"impureHostDeps": [],
24+
"noChroot": false,
25+
"preferLocalBuild": false,
26+
"requiredSystemFeatures": []
27+
},
1628
"outputs": {
1729
"out": {
1830
"path": "/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
"inputDrvs": {},
1313
"inputSrcs": [],
1414
"name": "advanced-attributes-structured-attrs-defaults",
15+
"options": {
16+
"additionalSandboxProfile": "",
17+
"allowLocalNetworking": false,
18+
"allowSubstitutes": true,
19+
"disallowedReferences": null,
20+
"disallowedRequisites": null,
21+
"impureEnvVars": [],
22+
"impureHostDeps": [],
23+
"noChroot": false,
24+
"preferLocalBuild": false,
25+
"requiredSystemFeatures": []
26+
},
1527
"outputs": {
1628
"dev": {
1729
"path": "/nix/store/8bazivnbipbyi569623skw5zm91z6kc2-advanced-attributes-structured-attrs-defaults-dev"

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@
2626
},
2727
"inputSrcs": [],
2828
"name": "advanced-attributes-structured-attrs",
29+
"options": {
30+
"additionalSandboxProfile": "sandcastle",
31+
"allowLocalNetworking": true,
32+
"allowSubstitutes": false,
33+
"disallowedReferences": null,
34+
"disallowedRequisites": null,
35+
"impureEnvVars": [
36+
"UNICORN"
37+
],
38+
"impureHostDeps": [
39+
"/usr/bin/ditto"
40+
],
41+
"noChroot": true,
42+
"preferLocalBuild": true,
43+
"requiredSystemFeatures": [
44+
"rainbow",
45+
"uid-range"
46+
]
47+
},
2948
"outputs": {
3049
"bin": {
3150
"path": "/nix/store/pbzb48v0ycf80jgligcp4n8z0rblna4n-advanced-attributes-structured-attrs-bin"

tests/unit/libstore/data/derivation/dynDerivationDeps.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
3434
],
3535
"name": "dyn-dep-derivation",
36+
"options": {
37+
"additionalSandboxProfile": "",
38+
"allowLocalNetworking": false,
39+
"allowSubstitutes": true,
40+
"disallowedReferences": null,
41+
"disallowedRequisites": null,
42+
"impureEnvVars": [],
43+
"impureHostDeps": [],
44+
"noChroot": false,
45+
"preferLocalBuild": false,
46+
"requiredSystemFeatures": []
47+
},
3648
"outputs": {},
3749
"system": "wasm-sel4"
3850
}

tests/unit/libstore/data/derivation/simple.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
2121
],
2222
"name": "simple-derivation",
23+
"options": {
24+
"additionalSandboxProfile": "",
25+
"allowLocalNetworking": false,
26+
"allowSubstitutes": true,
27+
"disallowedReferences": null,
28+
"disallowedRequisites": null,
29+
"impureEnvVars": [],
30+
"impureHostDeps": [],
31+
"noChroot": false,
32+
"preferLocalBuild": false,
33+
"requiredSystemFeatures": []
34+
},
2335
"outputs": {},
2436
"system": "wasm-sel4"
2537
}

0 commit comments

Comments
 (0)