aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-02-20 23:21:50 +0100
committerGitHub <noreply@github.com>2023-02-20 23:21:50 +0100
commitc7bd3a874f0a52fd33f8f930dd6450f5789a8c4b (patch)
tree876f9c5d6371c827eba2ad803d713d5b43471c99 /src/nix
parentdf6829e0d787772b0beaba38248fca8392bcaffe (diff)
parent7998686c00e05cc21f23dd3eae379f6a6c96c3af (diff)
Merge pull request #7863 from obsidiansystems/test-derivation-to-json
Move Derivation JSON printing logic to lib and test it
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/show-derivation.cc52
1 files changed, 2 insertions, 50 deletions
diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc
index af2e676a4..d1a516cad 100644
--- a/src/nix/show-derivation.cc
+++ b/src/nix/show-derivation.cc
@@ -54,56 +54,8 @@ struct CmdShowDerivation : InstallablesCommand
for (auto & drvPath : drvPaths) {
if (!drvPath.isDerivation()) continue;
- json& drvObj = jsonRoot[store->printStorePath(drvPath)];
-
- auto drv = store->readDerivation(drvPath);
-
- {
- json& outputsObj = drvObj["outputs"];
- outputsObj = json::object();
- for (auto & [_outputName, output] : drv.outputs) {
- auto & outputName = _outputName; // work around clang bug
- auto& outputObj = outputsObj[outputName];
- outputObj = json::object();
- std::visit(overloaded {
- [&](const DerivationOutput::InputAddressed & doi) {
- outputObj["path"] = store->printStorePath(doi.path);
- },
- [&](const DerivationOutput::CAFixed & dof) {
- outputObj["path"] = store->printStorePath(dof.path(*store, drv.name, outputName));
- outputObj["hashAlgo"] = dof.hash.printMethodAlgo();
- outputObj["hash"] = dof.hash.hash.to_string(Base16, false);
- },
- [&](const DerivationOutput::CAFloating & dof) {
- outputObj["hashAlgo"] = makeFileIngestionPrefix(dof.method) + printHashType(dof.hashType);
- },
- [&](const DerivationOutput::Deferred &) {},
- [&](const DerivationOutput::Impure & doi) {
- outputObj["hashAlgo"] = makeFileIngestionPrefix(doi.method) + printHashType(doi.hashType);
- outputObj["impure"] = true;
- },
- }, output.raw());
- }
- }
-
- {
- auto& inputsList = drvObj["inputSrcs"];
- inputsList = json::array();
- for (auto & input : drv.inputSrcs)
- inputsList.emplace_back(store->printStorePath(input));
- }
-
- {
- auto& inputDrvsObj = drvObj["inputDrvs"];
- inputDrvsObj = json::object();
- for (auto & input : drv.inputDrvs)
- inputDrvsObj[store->printStorePath(input.first)] = input.second;
- }
-
- drvObj["system"] = drv.platform;
- drvObj["builder"] = drv.builder;
- drvObj["args"] = drv.args;
- drvObj["env"] = drv.env;
+ jsonRoot[store->printStorePath(drvPath)] =
+ store->readDerivation(drvPath).toJSON(*store);
}
std::cout << jsonRoot.dump(2) << std::endl;
}