aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/buildable.cc33
-rw-r--r--src/libstore/buildable.hh34
2 files changed, 67 insertions, 0 deletions
diff --git a/src/libstore/buildable.cc b/src/libstore/buildable.cc
new file mode 100644
index 000000000..5cba45b1d
--- /dev/null
+++ b/src/libstore/buildable.cc
@@ -0,0 +1,33 @@
+#include "buildable.hh"
+#include "store-api.hh"
+
+#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;
+}
+
+}
diff --git a/src/libstore/buildable.hh b/src/libstore/buildable.hh
new file mode 100644
index 000000000..6177237be
--- /dev/null
+++ b/src/libstore/buildable.hh
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "util.hh"
+#include "path.hh"
+
+#include <optional>
+
+#include <nlohmann/json_fwd.hpp>
+
+namespace nix {
+
+class Store;
+
+struct BuildableOpaque {
+ StorePath path;
+ nlohmann::json toJSON(ref<Store> store) const;
+};
+
+struct BuildableFromDrv {
+ StorePath drvPath;
+ std::map<std::string, std::optional<StorePath>> outputs;
+ nlohmann::json toJSON(ref<Store> store) const;
+};
+
+typedef std::variant<
+ BuildableOpaque,
+ BuildableFromDrv
+> Buildable;
+
+typedef std::vector<Buildable> Buildables;
+
+nlohmann::json buildablesToJSON(const Buildables & buildables, ref<Store> store);
+
+}