mirror of
https://github.com/NixOS/nix
synced 2025-07-06 09:11:47 +02:00
Merge pull request #13349 from obsidiansystems/structured-attrs-json
Introduce top-level `structuredAttrs` field in JSON derivation format
This commit is contained in:
commit
d254c840b5
9 changed files with 169 additions and 21 deletions
|
@ -1333,6 +1333,11 @@ nlohmann::json Derivation::toJSON(const StoreDirConfig & store) const
|
|||
res["args"] = args;
|
||||
res["env"] = env;
|
||||
|
||||
if (auto it = env.find("__json"); it != env.end()) {
|
||||
res["env"].erase("__json");
|
||||
res["structuredAttrs"] = nlohmann::json::parse(it->second);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -1396,7 +1401,17 @@ Derivation Derivation::fromJSON(
|
|||
res.platform = getString(valueAt(json, "system"));
|
||||
res.builder = getString(valueAt(json, "builder"));
|
||||
res.args = getStringList(valueAt(json, "args"));
|
||||
res.env = getStringMap(valueAt(json, "env"));
|
||||
|
||||
auto envJson = valueAt(json, "env");
|
||||
try {
|
||||
res.env = getStringMap(envJson);
|
||||
} catch (Error & e) {
|
||||
e.addTrace({}, "while reading key 'env'");
|
||||
throw;
|
||||
}
|
||||
|
||||
if (auto structuredAttrs = get(json, "structuredAttrs"))
|
||||
res.env.insert_or_assign("__json", structuredAttrs->dump());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue