aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-18 17:39:02 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-18 17:39:02 +0100
commit4511f09b490fad4ce0dcfbcd7c4fd83b11e7df46 (patch)
treeb204381e6364d195c4db2c4f580482bfa961ff79 /src/nix
parentf8abbdd4565542464f31f4dc203a9c3e091b3536 (diff)
nix make-content-addressable: Add --json flag
Fixes #3274.
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/make-content-addressable.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index 524d467c2..f9c7fef3f 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -1,10 +1,12 @@
#include "command.hh"
#include "store-api.hh"
#include "references.hh"
+#include "common-args.hh"
+#include "json.hh"
using namespace nix;
-struct CmdMakeContentAddressable : StorePathsCommand
+struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
{
CmdMakeContentAddressable()
{
@@ -37,6 +39,9 @@ struct CmdMakeContentAddressable : StorePathsCommand
std::map<StorePath, StorePath> remappings;
+ auto jsonRoot = json ? std::make_unique<JSONObject>(std::cout) : nullptr;
+ auto jsonRewrites = json ? std::make_unique<JSONObject>(jsonRoot->object("rewrites")) : nullptr;
+
for (auto & path : paths) {
auto pathS = store->printStorePath(path);
auto oldInfo = store->queryPathInfo(path);
@@ -76,7 +81,8 @@ struct CmdMakeContentAddressable : StorePathsCommand
info.narSize = sink.s->size();
info.ca = makeFixedOutputCA(true, info.narHash);
- printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
+ if (!json)
+ printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
auto source = sinkToSource([&](Sink & nextSink) {
RewritingSink rsink2(oldHashPart, storePathToHash(store->printStorePath(info.path)), nextSink);
@@ -86,6 +92,9 @@ struct CmdMakeContentAddressable : StorePathsCommand
store->addToStore(info, *source);
+ if (json)
+ jsonRewrites->attr(store->printStorePath(path), store->printStorePath(info.path));
+
remappings.insert_or_assign(std::move(path), std::move(info.path));
}
}