aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/globals.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-09 22:39:04 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-17 12:41:04 -0400
commit2c8475600d16e463a9c63aa76aee9f6152128f14 (patch)
tree90b2080876965fd800aba469e78ece9800102f4b /src/libstore/globals.cc
parent3f9589f17e9e03aeb45b70f436c25227c728ba51 (diff)
Fix some issues with experimental config settings
Issues: 1. Features gated on disabled experimental settings should warn and be ignored, not silently succeed. 2. Experimental settings in the same config "batch" (file or env var) as the enabling of the experimental feature should work. 3. For (2), the order should not matter. These are analogous to the issues @roberth caught with my changes for arg handling, but they are instead for config handling. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r--src/libstore/globals.cc27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 1b38e32fb..4c66d08ee 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -22,6 +22,9 @@
#include <dlfcn.h>
#endif
+#include "config-impl.hh"
+
+
namespace nix {
@@ -192,18 +195,18 @@ NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, {
{SandboxMode::smDisabled, false},
});
-template<> void BaseSetting<SandboxMode>::set(const std::string & str, bool append)
+template<> SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str) const
{
- if (str == "true") value = smEnabled;
- else if (str == "relaxed") value = smRelaxed;
- else if (str == "false") value = smDisabled;
+ if (str == "true") return smEnabled;
+ else if (str == "relaxed") return smRelaxed;
+ else if (str == "false") return smDisabled;
else throw UsageError("option '%s' has invalid value '%s'", name, str);
}
-template<> bool BaseSetting<SandboxMode>::isAppendable()
+template<> struct BaseSetting<SandboxMode>::trait
{
- return false;
-}
+ static constexpr bool appendable = false;
+};
template<> std::string BaseSetting<SandboxMode>::to_string() const
{
@@ -235,23 +238,23 @@ template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::s
});
}
-void MaxBuildJobsSetting::set(const std::string & str, bool append)
+unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
{
- if (str == "auto") value = std::max(1U, std::thread::hardware_concurrency());
+ if (str == "auto") return std::max(1U, std::thread::hardware_concurrency());
else {
if (auto n = string2Int<decltype(value)>(str))
- value = *n;
+ return *n;
else
throw UsageError("configuration setting '%s' should be 'auto' or an integer", name);
}
}
-void PluginFilesSetting::set(const std::string & str, bool append)
+Paths PluginFilesSetting::parse(const std::string & str) const
{
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);
+ return BaseSetting<Paths>::parse(str);
}