aboutsummaryrefslogtreecommitdiff
path: root/src/nix/show-derivation.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/show-derivation.cc')
-rw-r--r--src/nix/show-derivation.cc75
1 files changed, 7 insertions, 68 deletions
diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc
index fb46b4dbf..4a406ae08 100644
--- a/src/nix/show-derivation.cc
+++ b/src/nix/show-derivation.cc
@@ -5,10 +5,11 @@
#include "common-args.hh"
#include "store-api.hh"
#include "archive.hh"
-#include "json.hh"
#include "derivations.hh"
+#include <nlohmann/json.hpp>
using namespace nix;
+using json = nlohmann::json;
struct CmdShowDerivation : InstallablesCommand
{
@@ -38,7 +39,7 @@ struct CmdShowDerivation : InstallablesCommand
Category category() override { return catUtility; }
- void run(ref<Store> store) override
+ void run(ref<Store> store, Installables && installables) override
{
auto drvPaths = Installable::toDerivations(store, installables, true);
@@ -48,77 +49,15 @@ struct CmdShowDerivation : InstallablesCommand
drvPaths = std::move(closure);
}
- {
-
- JSONObject jsonRoot(std::cout, true);
+ json jsonRoot = json::object();
for (auto & drvPath : drvPaths) {
if (!drvPath.isDerivation()) continue;
- auto drvObj(jsonRoot.object(store->printStorePath(drvPath)));
-
- auto drv = store->readDerivation(drvPath);
-
- {
- auto outputsObj(drvObj.object("outputs"));
- for (auto & [_outputName, output] : drv.outputs) {
- auto & outputName = _outputName; // work around clang bug
- auto outputObj { outputsObj.object(outputName) };
- std::visit(overloaded {
- [&](const DerivationOutput::InputAddressed & doi) {
- outputObj.attr("path", store->printStorePath(doi.path));
- },
- [&](const DerivationOutput::CAFixed & dof) {
- outputObj.attr("path", store->printStorePath(dof.path(*store, drv.name, outputName)));
- outputObj.attr("hashAlgo", dof.hash.printMethodAlgo());
- outputObj.attr("hash", dof.hash.hash.to_string(Base16, false));
- },
- [&](const DerivationOutput::CAFloating & dof) {
- outputObj.attr("hashAlgo", makeFileIngestionPrefix(dof.method) + printHashType(dof.hashType));
- },
- [&](const DerivationOutput::Deferred &) {},
- [&](const DerivationOutput::Impure & doi) {
- outputObj.attr("hashAlgo", makeFileIngestionPrefix(doi.method) + printHashType(doi.hashType));
- outputObj.attr("impure", true);
- },
- }, output.raw());
- }
- }
-
- {
- auto inputsList(drvObj.list("inputSrcs"));
- for (auto & input : drv.inputSrcs)
- inputsList.elem(store->printStorePath(input));
- }
-
- {
- auto inputDrvsObj(drvObj.object("inputDrvs"));
- for (auto & input : drv.inputDrvs) {
- auto inputList(inputDrvsObj.list(store->printStorePath(input.first)));
- for (auto & outputId : input.second)
- inputList.elem(outputId);
- }
- }
-
- drvObj.attr("system", drv.platform);
- drvObj.attr("builder", drv.builder);
-
- {
- auto argsList(drvObj.list("args"));
- for (auto & arg : drv.args)
- argsList.elem(arg);
- }
-
- {
- auto envObj(drvObj.object("env"));
- for (auto & var : drv.env)
- envObj.attr(var.first, var.second);
- }
+ jsonRoot[store->printStorePath(drvPath)] =
+ store->readDerivation(drvPath).toJSON(*store);
}
-
- }
-
- std::cout << "\n";
+ logger->cout(jsonRoot.dump(2));
}
};