aboutsummaryrefslogtreecommitdiff
path: root/src/libmain
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-05-26 11:46:42 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-05-26 11:46:42 -0400
commit0f3f90107174c74e9416c58b5989047dd40fc61f (patch)
tree5e0d25c902f8ddf906fbad016e5dbd7634037ed9 /src/libmain
parentc2f33edd1f30f5c7c54780636104bdef318d65db (diff)
parent3d3c219d917525b0a131c4332dd65eadfc818f49 (diff)
Merge remote-tracking branch 'origin/master' into more-rust-ffi
Diffstat (limited to 'src/libmain')
-rw-r--r--src/libmain/common-args.cc68
-rw-r--r--src/libmain/local.mk2
-rw-r--r--src/libmain/shared.cc66
3 files changed, 75 insertions, 61 deletions
diff --git a/src/libmain/common-args.cc b/src/libmain/common-args.cc
index 9e1d7cee6..51e199ea5 100644
--- a/src/libmain/common-args.cc
+++ b/src/libmain/common-args.cc
@@ -6,43 +6,47 @@ namespace nix {
MixCommonArgs::MixCommonArgs(const string & programName)
: programName(programName)
{
- mkFlag()
- .longName("verbose")
- .shortName('v')
- .description("increase verbosity level")
- .handler([]() { verbosity = (Verbosity) (verbosity + 1); });
-
- mkFlag()
- .longName("quiet")
- .description("decrease verbosity level")
- .handler([]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; });
-
- mkFlag()
- .longName("debug")
- .description("enable debug output")
- .handler([]() { verbosity = lvlDebug; });
-
- mkFlag()
- .longName("option")
- .labels({"name", "value"})
- .description("set a Nix configuration option (overriding nix.conf)")
- .arity(2)
- .handler([](std::vector<std::string> ss) {
+ addFlag({
+ .longName = "verbose",
+ .shortName = 'v',
+ .description = "increase verbosity level",
+ .handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }},
+ });
+
+ addFlag({
+ .longName = "quiet",
+ .description = "decrease verbosity level",
+ .handler = {[]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }},
+ });
+
+ addFlag({
+ .longName = "debug",
+ .description = "enable debug output",
+ .handler = {[]() { verbosity = lvlDebug; }},
+ });
+
+ addFlag({
+ .longName = "option",
+ .description = "set a Nix configuration option (overriding nix.conf)",
+ .labels = {"name", "value"},
+ .handler = {[](std::string name, std::string value) {
try {
- globalConfig.set(ss[0], ss[1]);
+ globalConfig.set(name, value);
} catch (UsageError & e) {
warn(e.what());
}
- });
-
- mkFlag()
- .longName("max-jobs")
- .shortName('j')
- .label("jobs")
- .description("maximum number of parallel builds")
- .handler([=](std::string s) {
+ }},
+ });
+
+ addFlag({
+ .longName = "max-jobs",
+ .shortName = 'j',
+ .description = "maximum number of parallel builds",
+ .labels = Strings{"jobs"},
+ .handler = {[=](std::string s) {
settings.set("max-jobs", s);
- });
+ }}
+ });
std::string cat = "config";
globalConfig.convertToArgs(*this, cat);
diff --git a/src/libmain/local.mk b/src/libmain/local.mk
index 0c80f5a0a..a8eed6c65 100644
--- a/src/libmain/local.mk
+++ b/src/libmain/local.mk
@@ -6,6 +6,8 @@ libmain_DIR := $(d)
libmain_SOURCES := $(wildcard $(d)/*.cc)
+libmain_CXXFLAGS += -I src/libutil -I src/libstore
+
libmain_LDFLAGS = $(OPENSSL_LIBS)
libmain_LIBS = libstore libutil
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index d41e772e9..70d1f0186 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -155,7 +155,7 @@ void initNix()
sshd). This breaks build users because they don't have access
to the TMPDIR, in particular in ‘nix-store --serve’. */
#if __APPLE__
- if (getuid() == 0 && hasPrefix(getEnv("TMPDIR").value_or("/tmp"), "/var/folders/"))
+ if (hasPrefix(getEnv("TMPDIR").value_or("/tmp"), "/var/folders/"))
unsetenv("TMPDIR");
#endif
}
@@ -165,28 +165,32 @@ LegacyArgs::LegacyArgs(const std::string & programName,
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
: MixCommonArgs(programName), parseArg(parseArg)
{
- mkFlag()
- .longName("no-build-output")
- .shortName('Q')
- .description("do not show build output")
- .set(&settings.verboseBuild, false);
-
- mkFlag()
- .longName("keep-failed")
- .shortName('K')
- .description("keep temporary directories of failed builds")
- .set(&(bool&) settings.keepFailed, true);
-
- mkFlag()
- .longName("keep-going")
- .shortName('k')
- .description("keep going after a build fails")
- .set(&(bool&) settings.keepGoing, true);
-
- mkFlag()
- .longName("fallback")
- .description("build from source if substitution fails")
- .set(&(bool&) settings.tryFallback, true);
+ addFlag({
+ .longName = "no-build-output",
+ .shortName = 'Q',
+ .description = "do not show build output",
+ .handler = {&settings.verboseBuild, false},
+ });
+
+ addFlag({
+ .longName = "keep-failed",
+ .shortName ='K',
+ .description = "keep temporary directories of failed builds",
+ .handler = {&(bool&) settings.keepFailed, true},
+ });
+
+ addFlag({
+ .longName = "keep-going",
+ .shortName ='k',
+ .description = "keep going after a build fails",
+ .handler = {&(bool&) settings.keepGoing, true},
+ });
+
+ addFlag({
+ .longName = "fallback",
+ .description = "build from source if substitution fails",
+ .handler = {&(bool&) settings.tryFallback, true},
+ });
auto intSettingAlias = [&](char shortName, const std::string & longName,
const std::string & description, const std::string & dest) {
@@ -205,11 +209,12 @@ LegacyArgs::LegacyArgs(const std::string & programName,
mkFlag(0, "no-gc-warning", "disable warning about not using '--add-root'",
&gcWarning, false);
- mkFlag()
- .longName("store")
- .label("store-uri")
- .description("URI of the Nix store to use")
- .dest(&(std::string&) settings.storeUri);
+ addFlag({
+ .longName = "store",
+ .description = "URI of the Nix store to use",
+ .labels = {"store-uri"},
+ .handler = {&(std::string&) settings.storeUri},
+ });
}
@@ -260,7 +265,10 @@ void printVersion(const string & programName)
cfg.push_back("signed-caches");
#endif
std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n";
- std::cout << "Configuration file: " << settings.nixConfDir + "/nix.conf" << "\n";
+ std::cout << "System configuration file: " << settings.nixConfDir + "/nix.conf" << "\n";
+ std::cout << "User configuration files: " <<
+ concatStringsSep(":", settings.nixUserConfFiles)
+ << "\n";
std::cout << "Store directory: " << settings.nixStore << "\n";
std::cout << "State directory: " << settings.nixStateDir << "\n";
}