diff options
author | Alois Wohlschlager <alois1@gmx-topmail.de> | 2024-09-02 20:09:35 +0200 |
---|---|---|
committer | Alois Wohlschlager <alois1@gmx-topmail.de> | 2024-10-15 19:55:50 +0200 |
commit | 4dbbd721eb9db75d4968a624b8cb9e75e979a144 (patch) | |
tree | ceee38ee4fc2acc806c124c65a8824f7db52e5c5 /src | |
parent | f6077314fa6aff862758095bb55fe844e9162a1d (diff) |
treewide: consistently mark overridden settings as such
Only overridden settings are sent to the daemon, and we're going to do the same
for the build hook to. It needs to be ensured that overridden settings are in
fact consistently marked as such, so that they actually get sent.
Change-Id: I7cd58d925702f86cf2c35ad121eb191ceb62a355
Diffstat (limited to 'src')
-rw-r--r-- | src/legacy/nix-store.cc | 14 | ||||
-rw-r--r-- | src/libcmd/common-eval-args.cc | 2 | ||||
-rw-r--r-- | src/libcmd/installables.cc | 4 | ||||
-rw-r--r-- | src/libcmd/repl.cc | 4 | ||||
-rw-r--r-- | src/libexpr/eval-settings.cc | 2 | ||||
-rw-r--r-- | src/libmain/shared.cc | 8 | ||||
-rw-r--r-- | src/libstore/builtins/fetchurl.cc | 4 | ||||
-rw-r--r-- | src/libstore/daemon.cc | 19 | ||||
-rw-r--r-- | src/libstore/globals.cc | 18 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 1 | ||||
-rw-r--r-- | src/libutil/config-impl.hh | 12 | ||||
-rw-r--r-- | src/libutil/config.cc | 5 | ||||
-rw-r--r-- | src/libutil/config.hh | 17 | ||||
-rw-r--r-- | src/nix/flake.cc | 4 | ||||
-rw-r--r-- | src/nix/main.cc | 34 | ||||
-rw-r--r-- | src/nix/repl.cc | 2 | ||||
-rw-r--r-- | src/nix/upgrade-nix.cc | 2 |
17 files changed, 72 insertions, 80 deletions
diff --git a/src/legacy/nix-store.cc b/src/legacy/nix-store.cc index e42aa4065..d4742f61f 100644 --- a/src/legacy/nix-store.cc +++ b/src/legacy/nix-store.cc @@ -831,12 +831,12 @@ static void opServe(Strings opFlags, Strings opArgs) // FIXME: changing options here doesn't work if we're // building through the daemon. verbosity = lvlError; - settings.keepLog = false; - settings.useSubstitutes = false; - settings.maxSilentTime = readInt(in); - settings.buildTimeout = readInt(in); + settings.keepLog.override(false); + settings.useSubstitutes.override(false); + settings.maxSilentTime.override(readInt(in)); + settings.buildTimeout.override(readInt(in)); if (GET_PROTOCOL_MINOR(clientVersion) >= 2) - settings.maxLogSize = readNum<unsigned long>(in); + settings.maxLogSize.override(readNum<unsigned long>(in)); if (GET_PROTOCOL_MINOR(clientVersion) >= 3) { auto nrRepeats = readInt(in); if (nrRepeats != 0) { @@ -850,10 +850,10 @@ static void opServe(Strings opFlags, Strings opArgs) // asked for. readInt(in); - settings.runDiffHook = true; + settings.runDiffHook.override(true); } if (GET_PROTOCOL_MINOR(clientVersion) >= 7) { - settings.keepFailed = (bool) readInt(in); + settings.keepFailed.override((bool) readInt(in)); } }; diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index cbb7edbdd..089ad31d9 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -137,7 +137,7 @@ MixEvalArgs::MixEvalArgs() .description = "Allow access to mutable paths and repositories.", .category = category, .handler = {[&]() { - evalSettings.pureEval = false; + evalSettings.pureEval.override(false); }}, }); diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 711cf1b07..b81d4e0fd 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -212,7 +212,7 @@ void SourceExprCommand::completeInstallable(AddCompletions & completions, std::s if (file) { completions.setType(AddCompletions::Type::Attrs); - evalSettings.pureEval = false; + evalSettings.pureEval.override(false); auto state = getEvalState(); Expr & e = state->parseExprFromFile( resolveExprPath(state->checkSourcePath(lookupFileArg(*state, *file))) @@ -435,7 +435,7 @@ Installables SourceExprCommand::parseInstallables( throw UsageError("'--file' and '--expr' are exclusive"); // FIXME: backward compatibility hack - if (file) evalSettings.pureEval = false; + if (file) evalSettings.pureEval.override(false); auto state = getEvalState(); auto vFile = state->allocValue(); diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index ce19bc1eb..9d7fd47dc 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -817,10 +817,10 @@ ProcessLineResult NixRepl::processLine(std::string line) else if (command == ":te" || command == ":trace-enable") { if (arg == "false" || (arg == "" && loggerSettings.showTrace)) { std::cout << "not showing error traces\n"; - loggerSettings.showTrace = false; + loggerSettings.showTrace.override(false); } else if (arg == "true" || (arg == "" && !loggerSettings.showTrace)) { std::cout << "showing error traces\n"; - loggerSettings.showTrace = true; + loggerSettings.showTrace.override(true); } else { throw Error("unexpected argument '%s' to %s", arg, command); }; diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc index 0bdf1b9a5..a31618929 100644 --- a/src/libexpr/eval-settings.cc +++ b/src/libexpr/eval-settings.cc @@ -47,7 +47,7 @@ static Strings parseNixPath(const std::string & s) EvalSettings::EvalSettings() { auto var = getEnv("NIX_PATH"); - if (var) nixPath = parseNixPath(*var); + if (var) nixPath.setDefault(parseNixPath(*var)); } Strings EvalSettings::getDefaultNixPath() diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 029b457b1..77c497237 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -196,20 +196,20 @@ LegacyArgs::LegacyArgs(const std::string & programName, .longName = "keep-failed", .shortName ='K', .description = "Keep temporary directories of failed builds.", - .handler = {&(bool&) settings.keepFailed, true}, + .handler = {[&]() { settings.keepFailed.override(true); }}, }); addFlag({ .longName = "keep-going", .shortName ='k', .description = "Keep going after a build fails.", - .handler = {&(bool&) settings.keepGoing, true}, + .handler = {[&]() { settings.keepGoing.override(true); }}, }); addFlag({ .longName = "fallback", .description = "Build from source if substitution fails.", - .handler = {&(bool&) settings.tryFallback, true}, + .handler = {[&]() { settings.tryFallback.override(true); }}, }); auto intSettingAlias = [&](char shortName, const std::string & longName, @@ -247,7 +247,7 @@ LegacyArgs::LegacyArgs(const std::string & programName, .longName = "store", .description = "The URL of the Nix store to use.", .labels = {"store-uri"}, - .handler = {&(std::string&) settings.storeUri}, + .handler = {[&](std::string storeUri) { settings.storeUri.override(storeUri); }}, }); } diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index b28eb01d0..69a9f993f 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -13,11 +13,11 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData, this to be stored in a file. It would be nice if we could just pass a pointer to the data. */ if (netrcData != "") { - settings.netrcFile = "netrc"; + settings.netrcFile.override("netrc"); writeFile(settings.netrcFile, netrcData, 0600); } - settings.caFile = "ca-certificates.crt"; + settings.caFile.override("ca-certificates.crt"); writeFile(settings.caFile, caFileData, 0600); auto getAttr = [&](const std::string & name) { diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index a9239197b..93b405c01 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -195,15 +195,15 @@ struct ClientSettings void apply(TrustedFlag trusted) { - settings.keepFailed = keepFailed; - settings.keepGoing = keepGoing; - settings.tryFallback = tryFallback; + settings.keepFailed.override(keepFailed); + settings.keepGoing.override(keepGoing); + settings.tryFallback.override(tryFallback); nix::verbosity = verbosity; - settings.maxBuildJobs.assign(maxBuildJobs); - settings.maxSilentTime = maxSilentTime; + settings.maxBuildJobs.override(maxBuildJobs); + settings.maxSilentTime.override(maxSilentTime); settings.verboseBuild = verboseBuild; - settings.buildCores = buildCores; - settings.useSubstitutes = useSubstitutes; + settings.buildCores.override(buildCores); + settings.useSubstitutes.override(useSubstitutes); for (auto & i : overrides) { auto & name(i.first); @@ -225,12 +225,13 @@ struct ClientSettings else warn("ignoring untrusted substituter '%s', you are not a trusted user.\n" "Run `man nix.conf` for more information on the `substituters` configuration option.", s); - res = subs; + res.override(subs); return true; }; try { - if (name == "ssh-auth-sock") // obsolete + if (name == "ssh-auth-sock" // obsolete + || name == "store") // the daemon *is* the store ; else if (name == experimentalFeatureSettings.experimentalFeatures.name) { // We don’t want to forward the experimental features to diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index f43b759d2..9377ac936 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -69,12 +69,12 @@ Settings::Settings() , nixManDir(canonPath(NIX_MAN_DIR)) , nixDaemonSocketFile(canonPath(getEnvNonEmpty("NIX_DAEMON_SOCKET_PATH").value_or(nixStateDir + DEFAULT_SOCKET_PATH))) { - buildUsersGroup = getuid() == 0 ? "nixbld" : ""; - allowSymlinkedStore = getEnv("NIX_IGNORE_SYMLINK_STORE") == "1"; + buildUsersGroup.setDefault(getuid() == 0 ? "nixbld" : ""); + allowSymlinkedStore.setDefault(getEnv("NIX_IGNORE_SYMLINK_STORE") == "1"); auto sslOverride = getEnv("NIX_SSL_CERT_FILE").value_or(getEnv("SSL_CERT_FILE").value_or("")); if (sslOverride != "") - caFile = sslOverride; + caFile.setDefault(sslOverride); /* Backwards compatibility. */ auto s = getEnv("NIX_REMOTE_SYSTEMS"); @@ -82,17 +82,17 @@ Settings::Settings() Strings ss; for (auto & p : tokenizeString<Strings>(*s, ":")) ss.push_back("@" + p); - builders = concatStringsSep(" ", ss); + builders.setDefault(concatStringsSep(" ", ss)); } #if defined(__linux__) && defined(SANDBOX_SHELL) - sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL); + sandboxPaths.setDefault(tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL)); #endif /* chroot-like behavior from Apple's sandbox */ #if __APPLE__ - sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib"); - allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh"); + sandboxPaths.setDefault(tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib")); + allowedImpureHostPrefixes.setDefault(tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh")); #endif /* Set the build hook location @@ -118,10 +118,10 @@ Settings::Settings() if (!pathExists(nixExePath)) { nixExePath = getSelfExe().value_or("nix"); } - buildHook = { + buildHook.setDefault(Strings { nixExePath, "__build-remote", - }; + }); } void loadConfFile() diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index a9f9818be..ff3722085 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -139,6 +139,7 @@ void RemoteStore::setOptions(Connection & conn) overrides.erase(loggerSettings.showTrace.name); overrides.erase(experimentalFeatureSettings.experimentalFeatures.name); overrides.erase(settings.pluginFiles.name); + overrides.erase(settings.storeUri.name); // the daemon *is* the store conn.to << overrides.size(); for (auto & i : overrides) conn.to << i.first << i.second.value; diff --git a/src/libutil/config-impl.hh b/src/libutil/config-impl.hh index 748107b6e..2342c9a03 100644 --- a/src/libutil/config-impl.hh +++ b/src/libutil/config-impl.hh @@ -65,6 +65,7 @@ void BaseSetting<T>::appendOrSet(T newValue, bool append, const ApplyConfigOptio "using default `appendOrSet` implementation with an appendable type"); assert(!append); + overridden = true; value = std::move(newValue); } @@ -85,6 +86,13 @@ void BaseSetting<T>::set(const std::string & str, bool append, const ApplyConfig } } +template<typename T> +void BaseSetting<T>::override(const T & v) +{ + overridden = true; + value = v; +} + template<> void BaseSetting<bool>::convertToArg(Args & args, const std::string & category); template<typename T> @@ -95,7 +103,7 @@ void BaseSetting<T>::convertToArg(Args & args, const std::string & category) .description = fmt("Set the `%s` setting.", name), .category = category, .labels = {"value"}, - .handler = {[this](std::string s) { overridden = true; set(s); }}, + .handler = {[this](std::string s) { set(s); }}, .experimentalFeature = experimentalFeature, }); @@ -105,7 +113,7 @@ void BaseSetting<T>::convertToArg(Args & args, const std::string & category) .description = fmt("Append to the `%s` setting.", name), .category = category, .labels = {"value"}, - .handler = {[this](std::string s) { overridden = true; set(s, true); }}, + .handler = {[this](std::string s) { set(s, true); }}, .experimentalFeature = experimentalFeature, }); } diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 778da1413..f600a10ca 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -32,7 +32,6 @@ bool Config::set(const std::string & name, const std::string & value, const Appl return false; } i->second.setting->set(value, append, options); - i->second.setting->overridden = true; return true; } @@ -46,7 +45,6 @@ void Config::addSetting(AbstractSetting * setting) if (auto i = unknownSettings.find(setting->name); i != unknownSettings.end()) { setting->set(std::move(i->second)); - setting->overridden = true; unknownSettings.erase(i); set = true; } @@ -58,7 +56,6 @@ void Config::addSetting(AbstractSetting * setting) alias, setting->name); else { setting->set(std::move(i->second)); - setting->overridden = true; unknownSettings.erase(i); set = true; } @@ -80,7 +77,7 @@ void AbstractConfig::reapplyUnknownSettings() { auto unknownSettings2 = std::move(unknownSettings); unknownSettings = {}; - for (auto & s : unknownSettings2) + for (auto & s : unknownSettings2) set(s.first, s.second); } diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 59cc281c5..b3dcc122f 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -218,6 +218,7 @@ protected: virtual void convertToArg(Args & args, const std::string & category); bool isOverridden() const; + }; /** @@ -267,16 +268,12 @@ public: { } operator const T &() const { return value; } - operator T &() { return value; } const T & get() const { return value; } template<typename U> bool operator ==(const U & v2) const { return value == v2; } template<typename U> bool operator !=(const U & v2) const { return value != v2; } template<typename U> - void operator =(const U & v) { assign(v); } - virtual void assign(const T & v) { value = v; } - template<typename U> void setDefault(const U & v) { if (!overridden) value = v; } /** @@ -287,6 +284,8 @@ public: */ void set(const std::string & str, bool append = false, const ApplyConfigOptions & options = {}) override final; + void override(const T & v); + /** * C++ trick; This is template-specialized to compile-time indicate whether * the type is appendable. @@ -299,12 +298,6 @@ public: */ bool isAppendable() override final; - virtual void override(const T & v) - { - overridden = true; - value = v; - } - std::string to_string() const override; void convertToArg(Args & args, const std::string & category) override; @@ -349,8 +342,6 @@ public: : Setting(options, def, name, description, aliases, documentDefault, std::move(experimentalFeature), true) { } - - void operator =(const T & v) { this->assign(v); } }; /** @@ -375,8 +366,6 @@ public: } T parse(const std::string & str, const ApplyConfigOptions & options) const override; - - void operator =(const T & v) { this->assign(v); } }; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 0c704a995..1dc13fb3f 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -116,7 +116,7 @@ public: void run(nix::ref<nix::Store> store) override { - settings.tarballTtl = 0; + settings.tarballTtl.override(0); auto updateAll = lockFlags.inputUpdates.empty(); lockFlags.recreateLockFile = updateAll; @@ -158,7 +158,7 @@ struct CmdFlakeLock : FlakeCommand void run(nix::ref<nix::Store> store) override { - settings.tarballTtl = 0; + settings.tarballTtl.override(0); lockFlags.writeLockFile = true; lockFlags.applyNixConfig = true; diff --git a/src/nix/main.cc b/src/nix/main.cc index fdd3ac2ae..cf1f876dd 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -247,8 +247,8 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel) { auto mdName = subcommand.empty() ? "nix" : fmt("nix3-%s", concatStringsSep("-", subcommand)); - evalSettings.restrictEval = false; - evalSettings.pureEval = false; + evalSettings.restrictEval.override(false); + evalSettings.pureEval.override(false); EvalState state({}, openStore("dummy://")); auto vGenerateManpage = state.allocValue(); @@ -389,7 +389,7 @@ void mainWrapped(int argc, char * * argv) if (legacy) return legacy(argc, argv); } - evalSettings.pureEval = true; + evalSettings.pureEval.setDefault(true); setLogFormat(LogFormat::bar); settings.verboseBuild = false; @@ -408,11 +408,11 @@ void mainWrapped(int argc, char * * argv) } if (argc == 2 && std::string(argv[1]) == "__dump-language") { - experimentalFeatureSettings.experimentalFeatures = ExperimentalFeatures{} + experimentalFeatureSettings.experimentalFeatures.override(ExperimentalFeatures{} | Xp::Flakes | Xp::FetchClosure - | Xp::DynamicDerivations; - evalSettings.pureEval = false; + | Xp::DynamicDerivations); + evalSettings.pureEval.override(false); EvalState state({}, openStore("dummy://")); auto res = nlohmann::json::object(); res["builtins"] = ({ @@ -513,24 +513,20 @@ void mainWrapped(int argc, char * * argv) if (!args.useNet) { // FIXME: should check for command line overrides only. - if (!settings.useSubstitutes.overridden) - settings.useSubstitutes = false; - if (!settings.tarballTtl.overridden) - settings.tarballTtl = std::numeric_limits<unsigned int>::max(); - if (!fileTransferSettings.tries.overridden) - fileTransferSettings.tries = 0; - if (!fileTransferSettings.connectTimeout.overridden) - fileTransferSettings.connectTimeout = 1; + settings.useSubstitutes.setDefault(false); + settings.tarballTtl.setDefault(std::numeric_limits<unsigned int>::max()); + fileTransferSettings.tries.setDefault(0); + fileTransferSettings.connectTimeout.setDefault(1); } if (args.refresh) { - settings.tarballTtl = 0; - settings.ttlNegativeNarInfoCache = 0; - settings.ttlPositiveNarInfoCache = 0; + settings.tarballTtl.override(0); + settings.ttlNegativeNarInfoCache.override(0); + settings.ttlPositiveNarInfoCache.override(0); } - if (args.command->second->forceImpureByDefault() && !evalSettings.pureEval.overridden) { - evalSettings.pureEval = false; + if (args.command->second->forceImpureByDefault()) { + evalSettings.pureEval.setDefault(false); } args.command->second->run(); } diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 88aeed859..13186277e 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -10,7 +10,7 @@ namespace nix { struct CmdRepl : RawInstallablesCommand { CmdRepl() { - evalSettings.pureEval = false; + evalSettings.pureEval.override(false); } /** diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index 15c5960d4..19f598874 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -72,7 +72,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand void run(ref<Store> store) override { - evalSettings.pureEval = true; + evalSettings.pureEval.override(true); if (profileDir == "") { profileDir = getProfileDir(store); |