nix-super/src/nix/show-derivation.cc

65 lines
1.6 KiB
C++
Raw Normal View History

// FIXME: integrate this with nix path-info?
2020-07-24 21:44:31 +03:00
// FIXME: rename to 'nix store show-derivation' or 'nix debug show-derivation'?
#include "command.hh"
#include "common-args.hh"
#include "store-api.hh"
#include "archive.hh"
#include "derivations.hh"
#include <nlohmann/json.hpp>
using namespace nix;
using json = nlohmann::json;
struct CmdShowDerivation : InstallablesCommand
{
bool recursive = false;
CmdShowDerivation()
{
2020-05-04 23:40:19 +03:00
addFlag({
.longName = "recursive",
.shortName = 'r',
.description = "Include the dependencies of the specified derivations.",
2020-05-04 23:40:19 +03:00
.handler = {&recursive, true}
});
}
std::string description() override
{
return "show the contents of a store derivation";
}
2020-12-10 20:14:18 +02:00
std::string doc() override
{
2020-12-10 20:14:18 +02:00
return
#include "show-derivation.md"
;
}
2020-05-05 16:18:23 +03:00
Category category() override { return catUtility; }
void run(ref<Store> store) override
{
2022-03-02 14:54:08 +02:00
auto drvPaths = Installable::toDerivations(store, installables, true);
if (recursive) {
StorePathSet closure;
store->computeFSClosure(drvPaths, closure);
drvPaths = std::move(closure);
}
json jsonRoot = json::object();
for (auto & drvPath : drvPaths) {
if (!drvPath.isDerivation()) continue;
jsonRoot[store->printStorePath(drvPath)] =
store->readDerivation(drvPath).toJSON(*store);
}
logger->cout(jsonRoot.dump(2));
}
};
static auto rCmdShowDerivation = registerCommand<CmdShowDerivation>("show-derivation");