aboutsummaryrefslogtreecommitdiff
path: root/src/nix/realisation.cc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-03-09 10:11:25 +0100
committerregnat <rg@regnat.ovh>2021-03-09 10:16:44 +0100
commit89013bdd7ed4007871cc421315b51b7cada8edff (patch)
tree56f747c36acb81938aded0ba985881ecaa53ee39 /src/nix/realisation.cc
parent1c0e3e453d41b869e4ac7e25dc1c00c349a7c411 (diff)
Add a `nix realisation` command for working on realisations
Currently only has `nix realisation info`, more to come probably
Diffstat (limited to 'src/nix/realisation.cc')
-rw-r--r--src/nix/realisation.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/nix/realisation.cc b/src/nix/realisation.cc
new file mode 100644
index 000000000..9ee9ccb91
--- /dev/null
+++ b/src/nix/realisation.cc
@@ -0,0 +1,78 @@
+#include "command.hh"
+#include "common-args.hh"
+
+#include <nlohmann/json.hpp>
+
+using namespace nix;
+
+struct CmdRealisation : virtual NixMultiCommand
+{
+ CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
+ { }
+
+ std::string description() override
+ {
+ return "manipulate a Nix realisation";
+ }
+
+ Category category() override { return catUtility; }
+
+ void run() override
+ {
+ if (!command)
+ throw UsageError("'nix realisation' requires a sub-command.");
+ command->second->prepare();
+ command->second->run();
+ }
+};
+
+static auto rCmdRealisation = registerCommand<CmdRealisation>("realisation");
+
+struct CmdRealisationInfo : RealisedPathsCommand, MixJSON
+{
+ std::string description() override
+ {
+ return "query information about one or several realisations";
+ }
+
+ std::string doc() override
+ {
+ return
+ #include "realisation/info.md"
+ ;
+ }
+
+ Category category() override { return catSecondary; }
+
+ void run(ref<Store> store, std::vector<RealisedPath> paths) override
+ {
+ settings.requireExperimentalFeature("ca-derivations");
+ if (json) {
+ nlohmann::json res = nlohmann::json::array();
+ for (auto & path : paths) {
+ nlohmann::json currentPath;
+ if (auto realisation = std::get_if<Realisation>(&path.raw))
+ currentPath = realisation->toJSON();
+ else
+ currentPath["opaquePath"] = store->printStorePath(path.path());
+
+ res.push_back(currentPath);
+ }
+ std::cout << res.dump();
+ }
+ else {
+ for (auto & path : paths) {
+ if (auto realisation = std::get_if<Realisation>(&path.raw)) {
+ std::cout <<
+ realisation->id.to_string() << " " <<
+ store->printStorePath(realisation->outPath);
+ } else
+ std::cout << store->printStorePath(path.path());
+
+ std::cout << std::endl;
+ }
+ }
+ }
+};
+
+static auto rCmdRealisationInfo = registerCommand2<CmdRealisationInfo>({"realisation", "info"});