aboutsummaryrefslogtreecommitdiff
path: root/src/nix/installables.cc
diff options
context:
space:
mode:
authorMatthew Kenigsberg <matthewkenigsberg@gmail.com>2020-10-22 23:59:01 -0500
committerMatthew Kenigsberg <matthewkenigsberg@gmail.com>2020-11-11 10:27:02 -0600
commit8abb80a478116b10bf37162c71f602262de412a9 (patch)
tree4abd6da99826d85b4e9d10167eab2b585c868ef3 /src/nix/installables.cc
parent21830cb0447f2ad3d436a8b9df43222a787bb80e (diff)
Print built derivations as json for build
Add --json option to nix build to allow machine readable output on stdout with all built derivations Fixes #1930
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r--src/nix/installables.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 7473c9758..f385289e5 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -16,8 +16,35 @@
#include <regex>
#include <queue>
+#include <nlohmann/json.hpp>
+
namespace nix {
+nlohmann::json BuildableOpaque::toJSON(ref<Store> store) const {
+ nlohmann::json res;
+ res["path"] = store->printStorePath(path);
+ return res;
+}
+
+nlohmann::json BuildableFromDrv::toJSON(ref<Store> store) const {
+ nlohmann::json res;
+ res["drvPath"] = store->printStorePath(drvPath);
+ for (const auto& [output, path] : outputs) {
+ res["outputs"][output] = path ? store->printStorePath(*path) : "";
+ }
+ return res;
+}
+
+nlohmann::json buildablesToJSON(const Buildables & buildables, ref<Store> store) {
+ auto res = nlohmann::json::array();
+ for (const Buildable & buildable : buildables) {
+ std::visit([&res, store](const auto & buildable) {
+ res.push_back(buildable.toJSON(store));
+ }, buildable);
+ }
+ return res;
+}
+
void completeFlakeInputPath(
ref<EvalState> evalState,
const FlakeRef & flakeRef,