aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/globals.cc
diff options
context:
space:
mode:
authorrebecca “wiggles” turner <rbt@sent.as>2024-09-01 22:06:36 +0000
committerGerrit Code Review <gerrit@localhost>2024-09-01 22:06:36 +0000
commit02eb07cfd539c34c080cb1baf042e5e780c1fcc2 (patch)
tree0397ab434cce8b284a8d447594e2e1f3f35a1470 /src/libstore/globals.cc
parentd75df91f74b6819f674f0733143fdf32580af183 (diff)
parent690f07272e58bfe86d12adb0bd6c81c031f930fd (diff)
Merge changes I5566a985,I88cf53d3 into main
* changes: Support relative and `~/` paths in config settings Thread `ApplyConfigOptions` through config parsing
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r--src/libstore/globals.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index b534882de..c114e22dc 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -126,29 +126,30 @@ Settings::Settings()
void loadConfFile()
{
- auto applyConfigFile = [&](const Path & path) {
+ auto applyConfigFile = [&](const ApplyConfigOptions & options) {
try {
- std::string contents = readFile(path);
- globalConfig.applyConfig(contents, path);
- } catch (SysError &) { }
+ std::string contents = readFile(*options.path);
+ globalConfig.applyConfig(contents, options);
+ } catch (SysError &) {
+ }
};
- applyConfigFile(settings.nixConfDir + "/nix.conf");
+ applyConfigFile(ApplyConfigOptions{.path = settings.nixConfDir + "/nix.conf"});
/* We only want to send overrides to the daemon, i.e. stuff from
~/.nix/nix.conf or the command line. */
globalConfig.resetOverridden();
auto files = settings.nixUserConfFiles;
+ auto home = getHome();
for (auto file = files.rbegin(); file != files.rend(); file++) {
- applyConfigFile(*file);
+ applyConfigFile(ApplyConfigOptions{.path = *file, .home = home});
}
auto nixConfEnv = getEnv("NIX_CONFIG");
if (nixConfEnv.has_value()) {
- globalConfig.applyConfig(nixConfEnv.value(), "NIX_CONFIG");
+ globalConfig.applyConfig(nixConfEnv.value(), ApplyConfigOptions{.fromEnvVar = true});
}
-
}
std::vector<Path> getUserConfigFiles()
@@ -274,7 +275,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(SandboxMode, {
{SandboxMode::smDisabled, false},
});
-template<> SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str) const
+template<> SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (str == "true") return smEnabled;
else if (str == "relaxed") return smRelaxed;
@@ -317,7 +318,7 @@ template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::s
});
}
-unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
+unsigned int MaxBuildJobsSetting::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (str == "auto") return std::max(1U, std::thread::hardware_concurrency());
else {
@@ -325,15 +326,15 @@ unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
return *n;
else
throw UsageError("configuration setting '%s' should be 'auto' or an integer", name);
+ }
}
-}
-Paths PluginFilesSetting::parse(const std::string & str) const
+Paths PluginFilesSetting::parse(const std::string & str, const ApplyConfigOptions & options) const
{
if (pluginsLoaded)
throw UsageError("plugin-files set after plugins were loaded, you may need to move the flag before the subcommand");
- return BaseSetting<Paths>::parse(str);
+ return BaseSetting<Paths>::parse(str, options);
}