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.cc75
1 files changed, 50 insertions, 25 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 0daf374de..f076ffdb0 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -500,7 +500,7 @@ static bool keep(DrvInfo & drv)
static void installDerivations(Globals & globals,
const Strings & args, const Path & profile)
{
- debug(format("installing derivations"));
+ debug("installing derivations");
/* Get the set of user environment elements to be installed. */
DrvInfos newElems, newElemsTmp;
@@ -579,7 +579,7 @@ typedef enum { utLt, utLeq, utEq, utAlways } UpgradeType;
static void upgradeDerivations(Globals & globals,
const Strings & args, UpgradeType upgradeType)
{
- debug(format("upgrading derivations"));
+ debug("upgrading derivations");
/* Upgrade works as follows: we take all currently installed
derivations, and for any derivation matching any selector, look
@@ -768,7 +768,7 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
if (globals.dryRun) return;
globals.state->store->buildPaths(paths, globals.state->repair ? bmRepair : bmNormal);
- debug(format("switching to new user environment"));
+ debug("switching to new user environment");
Path generation = createGeneration(
ref<LocalFSStore>(store2),
globals.profile,
@@ -1093,7 +1093,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
try {
if (i.hasFailed()) continue;
- //Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath);
+ //Activity act(*logger, lvlDebug, "outputting query result '%1%'", i.attrPath);
if (globals.prebuiltOnly &&
!validPaths.count(i.queryOutPath()) &&
@@ -1229,11 +1229,11 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
xml.writeEmptyElement("meta", attrs2);
} else if (v->type() == nInt) {
attrs2["type"] = "int";
- attrs2["value"] = (format("%1%") % v->integer).str();
+ attrs2["value"] = fmt("%1%", v->integer);
xml.writeEmptyElement("meta", attrs2);
} else if (v->type() == nFloat) {
attrs2["type"] = "float";
- attrs2["value"] = (format("%1%") % v->fpoint).str();
+ attrs2["value"] = fmt("%1%", v->fpoint);
xml.writeEmptyElement("meta", attrs2);
} else if (v->type() == nBool) {
attrs2["type"] = "bool";
@@ -1337,11 +1337,11 @@ static void opListGenerations(Globals & globals, Strings opFlags, Strings opArgs
for (auto & i : gens) {
tm t;
if (!localtime_r(&i.creationTime, &t)) throw Error("cannot convert time");
- cout << format("%|4| %|4|-%|02|-%|02| %|02|:%|02|:%|02| %||\n")
- % i.number
- % (t.tm_year + 1900) % (t.tm_mon + 1) % t.tm_mday
- % t.tm_hour % t.tm_min % t.tm_sec
- % (i.number == curGen ? "(current)" : "");
+ logger->cout("%|4| %|4|-%|02|-%|02| %|02|:%|02|:%|02| %||",
+ i.number,
+ t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
+ t.tm_hour, t.tm_min, t.tm_sec,
+ i.number == curGen ? "(current)" : "");
}
}
@@ -1387,6 +1387,8 @@ static int main_nix_env(int argc, char * * argv)
{
Strings opFlags, opArgs;
Operation op = 0;
+ std::string opName;
+ bool showHelp = false;
RepairFlag repair = NoRepair;
std::string file;
@@ -1403,11 +1405,11 @@ static int main_nix_env(int argc, char * * argv)
try {
createDirs(globals.instSource.nixExprPath);
replaceSymlink(
- fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
+ defaultChannelsDir(),
globals.instSource.nixExprPath + "/channels");
if (getuid() != 0)
replaceSymlink(
- fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
+ rootChannelsDir(),
globals.instSource.nixExprPath + "/channels_root");
} catch (Error &) { }
}
@@ -1426,37 +1428,59 @@ static int main_nix_env(int argc, char * * argv)
Operation oldOp = op;
if (*arg == "--help")
- showManPage("nix-env");
+ showHelp = true;
else if (*arg == "--version")
op = opVersion;
- else if (*arg == "--install" || *arg == "-i")
+ else if (*arg == "--install" || *arg == "-i") {
op = opInstall;
+ opName = "-install";
+ }
else if (*arg == "--force-name") // undocumented flag for nix-install-package
globals.forceName = getArg(*arg, arg, end);
- else if (*arg == "--uninstall" || *arg == "-e")
+ else if (*arg == "--uninstall" || *arg == "-e") {
op = opUninstall;
- else if (*arg == "--upgrade" || *arg == "-u")
+ opName = "-uninstall";
+ }
+ else if (*arg == "--upgrade" || *arg == "-u") {
op = opUpgrade;
- else if (*arg == "--set-flag")
+ opName = "-upgrade";
+ }
+ else if (*arg == "--set-flag") {
op = opSetFlag;
- else if (*arg == "--set")
+ opName = arg->substr(1);
+ }
+ else if (*arg == "--set") {
op = opSet;
- else if (*arg == "--query" || *arg == "-q")
+ opName = arg->substr(1);
+ }
+ else if (*arg == "--query" || *arg == "-q") {
op = opQuery;
+ opName = "-query";
+ }
else if (*arg == "--profile" || *arg == "-p")
globals.profile = absPath(getArg(*arg, arg, end));
else if (*arg == "--file" || *arg == "-f")
file = getArg(*arg, arg, end);
- else if (*arg == "--switch-profile" || *arg == "-S")
+ else if (*arg == "--switch-profile" || *arg == "-S") {
op = opSwitchProfile;
- else if (*arg == "--switch-generation" || *arg == "-G")
+ opName = "-switch-profile";
+ }
+ else if (*arg == "--switch-generation" || *arg == "-G") {
op = opSwitchGeneration;
- else if (*arg == "--rollback")
+ opName = "-switch-generation";
+ }
+ else if (*arg == "--rollback") {
op = opRollback;
- else if (*arg == "--list-generations")
+ opName = arg->substr(1);
+ }
+ else if (*arg == "--list-generations") {
op = opListGenerations;
- else if (*arg == "--delete-generations")
+ opName = arg->substr(1);
+ }
+ else if (*arg == "--delete-generations") {
op = opDeleteGenerations;
+ opName = arg->substr(1);
+ }
else if (*arg == "--dry-run") {
printInfo("(dry run; not doing anything)");
globals.dryRun = true;
@@ -1485,6 +1509,7 @@ static int main_nix_env(int argc, char * * argv)
myArgs.parseCmdline(argvToStrings(argc, argv));
+ if (showHelp) showManPage("nix-env" + opName);
if (!op) throw UsageError("no operation specified");
auto store = openStore();