Include the name in the JSON for derivations

This is non-breaking change in the to-JSON direction. This *is* a
breaking change in the from-JSON direction, but we don't care, as that
is brand new in this PR.

`nix show-derivation --help` currently has the sole public documentation
of this format, it is updated accordingly.
This commit is contained in:
John Ericson 2023-03-30 11:06:52 -04:00
parent fe9cbe838c
commit b200784cec
4 changed files with 11 additions and 4 deletions

View file

@ -988,6 +988,8 @@ nlohmann::json Derivation::toJSON(const Store & store) const
{
nlohmann::json res = nlohmann::json::object();
res["name"] = name;
{
nlohmann::json & outputsObj = res["outputs"];
outputsObj = nlohmann::json::object();
@ -1020,17 +1022,19 @@ nlohmann::json Derivation::toJSON(const Store & store) const
Derivation Derivation::fromJSON(
const Store & store, std::string_view drvName,
const Store & store,
const nlohmann::json & json)
{
Derivation res;
res.name = json["name"];
{
auto & outputsObj = json["outputs"];
for (auto & [outputName, output] : outputsObj.items()) {
res.outputs.insert_or_assign(
outputName,
DerivationOutput::fromJSON(store, drvName, outputName, output));
DerivationOutput::fromJSON(store, res.name, outputName, output));
}
}

View file

@ -340,7 +340,6 @@ struct Derivation : BasicDerivation
nlohmann::json toJSON(const Store & store) const;
static Derivation fromJSON(
const Store & store,
std::string_view drvName,
const nlohmann::json & json);
GENERATE_CMP(Derivation,

View file

@ -98,12 +98,12 @@ TEST_JSON(impure,
Derivation { VAL }, \
Derivation::fromJSON( \
*store, \
DRV_NAME, \
STR ## _json)); \
}
TEST_JSON(simple,
R"({
"name": "my-derivation",
"inputSrcs": [
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
],
@ -126,6 +126,7 @@ TEST_JSON(simple,
})",
({
Derivation drv;
drv.name = "my-derivation";
drv.inputSrcs = {
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
};

View file

@ -51,6 +51,9 @@ The JSON output is a JSON object whose keys are the store paths of the
derivations, and whose values are a JSON object with the following
fields:
* `name`: The name of the derivation. This is used when calculating the
store paths of the derivation's outputs.
* `outputs`: Information about the output paths of the
derivation. This is a JSON object with one member per output, where
the key is the output name and the value is a JSON object with these