aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/globals.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-09-15 20:33:44 +0200
committerGitHub <noreply@github.com>2021-09-15 20:33:44 +0200
commit79152e307e7eef667c3de9c21571d017654a7c32 (patch)
tree67fd413bcf0b42c5ada7eddc41a04f7bd99df3a8 /src/libstore/globals.cc
parent7349f257da8278af9aae35544b15c9a204e2a57b (diff)
parent3b82c1a5fef521ebadea5df12384390c8c24100c (diff)
Merge pull request #5212 from mkenigs/auto-uid-allocation
Merge master into #3600
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r--src/libstore/globals.cc89
1 files changed, 77 insertions, 12 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 683fa5196..6934801e3 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -2,6 +2,8 @@
#include "util.hh"
#include "archive.hh"
#include "args.hh"
+#include "abstract-setting-to-json.hh"
+#include "compute-levels.hh"
#include <algorithm>
#include <map>
@@ -9,6 +11,8 @@
#include <dlfcn.h>
#include <sys/utsname.h>
+#include <nlohmann/json.hpp>
+
namespace nix {
@@ -22,7 +26,7 @@ namespace nix {
Settings settings;
-static GlobalConfig::Register r1(&settings);
+static GlobalConfig::Register rSettings(&settings);
Settings::Settings()
: nixPrefix(NIX_PREFIX)
@@ -39,6 +43,7 @@ Settings::Settings()
{
buildUsersGroup = getuid() == 0 ? "nixbld" : "";
lockCPU = getEnv("NIX_AFFINITY_HACK") == "1";
+ allowSymlinkedStore = getEnv("NIX_IGNORE_SYMLINK_STORE") == "1";
caFile = getEnv("NIX_SSL_CERT_FILE").value_or(getEnv("SSL_CERT_FILE").value_or(""));
if (caFile == "") {
@@ -76,12 +81,18 @@ void loadConfFile()
/* We only want to send overrides to the daemon, i.e. stuff from
~/.nix/nix.conf or the command line. */
- globalConfig.resetOverriden();
+ globalConfig.resetOverridden();
auto files = settings.nixUserConfFiles;
for (auto file = files.rbegin(); file != files.rend(); file++) {
globalConfig.applyConfigFile(*file);
}
+
+ auto nixConfEnv = getEnv("NIX_CONFIG");
+ if (nixConfEnv.has_value()) {
+ globalConfig.applyConfig(nixConfEnv.value(), "NIX_CONFIG");
+ }
+
}
std::vector<Path> getUserConfigFiles()
@@ -121,16 +132,48 @@ StringSet Settings::getDefaultSystemFeatures()
return features;
}
+StringSet Settings::getDefaultExtraPlatforms()
+{
+ StringSet extraPlatforms;
+
+ if (std::string{SYSTEM} == "x86_64-linux" && !isWSL1())
+ extraPlatforms.insert("i686-linux");
+
+#if __linux__
+ StringSet levels = computeLevels();
+ for (auto iter = levels.begin(); iter != levels.end(); ++iter)
+ extraPlatforms.insert(*iter + "-linux");
+#elif __APPLE__
+ // Rosetta 2 emulation layer can run x86_64 binaries on aarch64
+ // machines. Note that we can’t force processes from executing
+ // x86_64 in aarch64 environments or vice versa since they can
+ // always exec with their own binary preferences.
+ if (pathExists("/Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist")) {
+ if (std::string{SYSTEM} == "x86_64-darwin")
+ extraPlatforms.insert("aarch64-darwin");
+ else if (std::string{SYSTEM} == "aarch64-darwin")
+ extraPlatforms.insert("x86_64-darwin");
+ }
+#endif
+
+ return extraPlatforms;
+}
+
bool Settings::isExperimentalFeatureEnabled(const std::string & name)
{
auto & f = experimentalFeatures.get();
return std::find(f.begin(), f.end(), name) != f.end();
}
+MissingExperimentalFeature::MissingExperimentalFeature(std::string feature)
+ : Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", feature)
+ , missingFeature(feature)
+ {}
+
void Settings::requireExperimentalFeature(const std::string & name)
{
if (!isExperimentalFeatureEnabled(name))
- throw Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", name);
+ throw MissingExperimentalFeature(name);
}
bool Settings::isWSL1()
@@ -144,7 +187,13 @@ bool Settings::isWSL1()
const string nixVersion = PACKAGE_VERSION;
-template<> void BaseSetting<SandboxMode>::set(const std::string & str)
+NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, {
+ {SandboxMode::smEnabled, true},
+ {SandboxMode::smRelaxed, "relaxed"},
+ {SandboxMode::smDisabled, false},
+});
+
+template<> void BaseSetting<SandboxMode>::set(const std::string & str, bool append)
{
if (str == "true") value = smEnabled;
else if (str == "relaxed") value = smRelaxed;
@@ -152,6 +201,11 @@ template<> void BaseSetting<SandboxMode>::set(const std::string & str)
else throw UsageError("option '%s' has invalid value '%s'", name, str);
}
+template<> bool BaseSetting<SandboxMode>::isAppendable()
+{
+ return false;
+}
+
template<> std::string BaseSetting<SandboxMode>::to_string() const
{
if (value == smEnabled) return "true";
@@ -160,11 +214,6 @@ template<> std::string BaseSetting<SandboxMode>::to_string() const
else abort();
}
-template<> void BaseSetting<SandboxMode>::toJSON(JSONPlaceholder & out)
-{
- AbstractSetting::toJSON(out);
-}
-
template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & category)
{
args.addFlag({
@@ -187,16 +236,29 @@ template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::s
});
}
-void MaxBuildJobsSetting::set(const std::string & str)
+void MaxBuildJobsSetting::set(const std::string & str, bool append)
{
if (str == "auto") value = std::max(1U, std::thread::hardware_concurrency());
- else if (!string2Int(str, value))
- throw UsageError("configuration setting '%s' should be 'auto' or an integer", name);
+ else {
+ if (auto n = string2Int<decltype(value)>(str))
+ value = *n;
+ else
+ throw UsageError("configuration setting '%s' should be 'auto' or an integer", name);
+ }
+}
+
+
+void PluginFilesSetting::set(const std::string & str, bool append)
+{
+ if (pluginsLoaded)
+ throw UsageError("plugin-files set after plugins were loaded, you may need to move the flag before the subcommand");
+ BaseSetting<Paths>::set(str, append);
}
void initPlugins()
{
+ assert(!settings.pluginFiles.pluginsLoaded);
for (const auto & pluginFile : settings.pluginFiles.get()) {
Paths pluginFiles;
try {
@@ -222,6 +284,9 @@ void initPlugins()
unknown settings. */
globalConfig.reapplyUnknownSettings();
globalConfig.warnUnknownSettings();
+
+ /* Tell the user if they try to set plugin-files after we've already loaded */
+ settings.pluginFiles.pluginsLoaded = true;
}
}