aboutsummaryrefslogtreecommitdiff
path: root/src/nix-env/nix-env.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-env/nix-env.cc')
-rw-r--r--src/nix-env/nix-env.cc47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 9a68899cd..31823a966 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -12,7 +12,6 @@
#include "local-fs-store.hh"
#include "user-env.hh"
#include "util.hh"
-#include "json.hh"
#include "value-to-json.hh"
#include "xml-writer.hh"
#include "legacy.hh"
@@ -26,6 +25,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <nlohmann/json.hpp>
using namespace nix;
using std::cout;
@@ -647,7 +647,7 @@ static void upgradeDerivations(Globals & globals,
} else newElems.push_back(i);
} catch (Error & e) {
- e.addTrace(std::nullopt, "while trying to find an upgrade for '%s'", i.queryName());
+ e.addTrace(nullptr, "while trying to find an upgrade for '%s'", i.queryName());
throw;
}
}
@@ -911,53 +911,58 @@ static VersionDiff compareVersionAgainstSet(
static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool printOutPath, bool printMeta)
{
- JSONObject topObj(cout, true);
+ using nlohmann::json;
+ json topObj = json::object();
for (auto & i : elems) {
try {
if (i.hasFailed()) continue;
- JSONObject pkgObj = topObj.object(i.attrPath);
auto drvName = DrvName(i.queryName());
- pkgObj.attr("name", drvName.fullName);
- pkgObj.attr("pname", drvName.name);
- pkgObj.attr("version", drvName.version);
- pkgObj.attr("system", i.querySystem());
- pkgObj.attr("outputName", i.queryOutputName());
+ json &pkgObj = topObj[i.attrPath];
+ pkgObj = {
+ {"name", drvName.fullName},
+ {"pname", drvName.name},
+ {"version", drvName.version},
+ {"system", i.querySystem()},
+ {"outputName", i.queryOutputName()},
+ };
{
DrvInfo::Outputs outputs = i.queryOutputs(printOutPath);
- JSONObject outputObj = pkgObj.object("outputs");
+ json &outputObj = pkgObj["outputs"];
+ outputObj = json::object();
for (auto & j : outputs) {
if (j.second)
- outputObj.attr(j.first, globals.state->store->printStorePath(*j.second));
+ outputObj[j.first] = globals.state->store->printStorePath(*j.second);
else
- outputObj.attr(j.first, nullptr);
+ outputObj[j.first] = nullptr;
}
}
if (printMeta) {
- JSONObject metaObj = pkgObj.object("meta");
+ json &metaObj = pkgObj["meta"];
+ metaObj = json::object();
StringSet metaNames = i.queryMetaNames();
for (auto & j : metaNames) {
- auto placeholder = metaObj.placeholder(j);
Value * v = i.queryMeta(j);
if (!v) {
printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j);
- placeholder.write(nullptr);
+ metaObj[j] = nullptr;
} else {
PathSet context;
- printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context);
+ metaObj[j] = printValueAsJSON(*globals.state, true, *v, noPos, context);
}
}
}
} catch (AssertionError & e) {
printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName());
} catch (Error & e) {
- e.addTrace(std::nullopt, "while querying the derivation named '%1%'", i.queryName());
+ e.addTrace(nullptr, "while querying the derivation named '%1%'", i.queryName());
throw;
}
}
+ std::cout << topObj.dump(2);
}
@@ -1241,7 +1246,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
Attr & a(*attrs.find(i.name));
if(a.value->type() != nString) continue;
XMLAttrs attrs3;
- attrs3["type"] = i.name;
+ attrs3["type"] = globals.state->symbols[i.name];
attrs3["value"] = a.value->string.s;
xml.writeEmptyElement("string", attrs3);
}
@@ -1257,7 +1262,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
} catch (AssertionError & e) {
printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName());
} catch (Error & e) {
- e.addTrace(std::nullopt, "while querying the derivation named '%1%'", i.queryName());
+ e.addTrace(nullptr, "while querying the derivation named '%1%'", i.queryName());
throw;
}
}
@@ -1485,12 +1490,10 @@ static int main_nix_env(int argc, char * * argv)
if (globals.profile == "")
globals.profile = getDefaultProfile();
- op(globals, opFlags, opArgs);
+ op(globals, std::move(opFlags), std::move(opArgs));
globals.state->printStats();
- logger->stop();
-
return 0;
}
}