aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-03-30 11:06:52 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 08:34:58 -0400
commitb200784cec056da53378eb043cae4fad188e4e6f (patch)
tree1e9dcaf438a6b7f7348d811b9ec90a47f7befc14 /src/libstore
parentfe9cbe838c3d59e2768b92d8cab0e5a2674f5bfb (diff)
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.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derivations.cc8
-rw-r--r--src/libstore/derivations.hh1
-rw-r--r--src/libstore/tests/derivation.cc3
3 files changed, 8 insertions, 4 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index ea4abb352..9f74f1c30 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -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));
}
}
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 0722dc61d..38727d77a 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -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,
diff --git a/src/libstore/tests/derivation.cc b/src/libstore/tests/derivation.cc
index 8993cd80b..80ee52fd0 100644
--- a/src/libstore/tests/derivation.cc
+++ b/src/libstore/tests/derivation.cc
@@ -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"),
};