aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/derivations.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-02-28 12:46:00 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-02-28 12:46:00 -0500
commit5abd643c6d10f2cfa6e26652a9688a0263310094 (patch)
tree2fdb8bf147cb93430ba3ba79a473568e2584e497 /src/libstore/derivations.cc
parente68e8e3cee53ce7debd7c54b0d122d94d1b102a2 (diff)
parentd381248ec0847cacd918480e83a99287f814456a (diff)
Merge branch 'path-info' into ca-drv-exotic
Diffstat (limited to 'src/libstore/derivations.cc')
-rw-r--r--src/libstore/derivations.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index b19ee5ed1..5461f4a9c 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -6,6 +6,7 @@
#include "worker-protocol.hh"
#include "fs-accessor.hh"
#include <boost/container/small_vector.hpp>
+#include <nlohmann/json.hpp>
namespace nix {
@@ -887,4 +888,64 @@ std::optional<BasicDerivation> Derivation::tryResolve(
const Hash impureOutputHash = hashString(htSHA256, "impure");
+nlohmann::json DerivationOutput::toJSON(
+ const Store & store, std::string_view drvName, std::string_view outputName) const
+{
+ nlohmann::json res = nlohmann::json::object();
+ std::visit(overloaded {
+ [&](const DerivationOutput::InputAddressed & doi) {
+ res["path"] = store.printStorePath(doi.path);
+ },
+ [&](const DerivationOutput::CAFixed & dof) {
+ res["path"] = store.printStorePath(dof.path(store, drvName, outputName));
+ res["hashAlgo"] = printMethodAlgo(dof.ca);
+ res["hash"] = getContentAddressHash(dof.ca).to_string(Base16, false);
+ // FIXME print refs?
+ },
+ [&](const DerivationOutput::CAFloating & dof) {
+ res["hashAlgo"] = makeContentAddressingPrefix(dof.method) + printHashType(dof.hashType);
+ },
+ [&](const DerivationOutput::Deferred &) {},
+ [&](const DerivationOutput::Impure & doi) {
+ res["hashAlgo"] = makeContentAddressingPrefix(doi.method) + printHashType(doi.hashType);
+ res["impure"] = true;
+ },
+ }, raw());
+ return res;
+}
+
+nlohmann::json Derivation::toJSON(const Store & store) const
+{
+ nlohmann::json res = nlohmann::json::object();
+
+ {
+ nlohmann::json & outputsObj = res["outputs"];
+ outputsObj = nlohmann::json::object();
+ for (auto & [outputName, output] : outputs) {
+ outputsObj[outputName] = output.toJSON(store, name, outputName);
+ }
+ }
+
+ {
+ auto& inputsList = res["inputSrcs"];
+ inputsList = nlohmann::json ::array();
+ for (auto & input : inputSrcs)
+ inputsList.emplace_back(store.printStorePath(input));
+ }
+
+ {
+ auto& inputDrvsObj = res["inputDrvs"];
+ inputDrvsObj = nlohmann::json ::object();
+ for (auto & input : inputDrvs)
+ inputDrvsObj[store.printStorePath(input.first)] = input.second;
+ }
+
+ res["system"] = platform;
+ res["builder"] = builder;
+ res["args"] = args;
+ res["env"] = env;
+
+ return res;
+}
+
}