aboutsummaryrefslogtreecommitdiff
path: root/src/nix/derivation-show.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-02 14:05:53 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 08:34:58 -0400
commit27597f813126bf0e866c6f6ba35dc7d3761843f8 (patch)
tree580f2662e642b605faaaba317156b6ab50e67170 /src/nix/derivation-show.cc
parent2b98af2e62f8a70cfa132f9bac7049a198309df8 (diff)
Rename files to reflect new `nix derivation show` name
This will match the files we added for `nix add derivation` in the rest of this PR.
Diffstat (limited to 'src/nix/derivation-show.cc')
-rw-r--r--src/nix/derivation-show.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/nix/derivation-show.cc b/src/nix/derivation-show.cc
new file mode 100644
index 000000000..bf637246d
--- /dev/null
+++ b/src/nix/derivation-show.cc
@@ -0,0 +1,64 @@
+// FIXME: integrate this with nix path-info?
+// FIXME: rename to 'nix store derivation show' or 'nix debug derivation show'?
+
+#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()
+ {
+ addFlag({
+ .longName = "recursive",
+ .shortName = 'r',
+ .description = "Include the dependencies of the specified derivations.",
+ .handler = {&recursive, true}
+ });
+ }
+
+ std::string description() override
+ {
+ return "show the contents of a store derivation";
+ }
+
+ std::string doc() override
+ {
+ return
+ #include "derivation-show.md"
+ ;
+ }
+
+ Category category() override { return catUtility; }
+
+ void run(ref<Store> store, Installables && installables) override
+ {
+ 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 = registerCommand2<CmdShowDerivation>({"derivation", "show"});