diff options
author | Rebecca Turner <rbt@sent.as> | 2024-08-25 11:58:10 -0700 |
---|---|---|
committer | Rebecca Turner <rbt@sent.as> | 2024-08-25 15:54:22 -0700 |
commit | 5fc6fcb31035f79a8e590f07d73dc6cc592e9e29 (patch) | |
tree | a47f804e3b3d74688e1dab6b6fd952664e0ef88b /src/libstore/globals.cc | |
parent | b6884388a1281d70bb4e5bb12e1cadd34bb832f0 (diff) |
Thread `ApplyConfigOptions` through config parsing
This makes no changes to logic but makes the `ApplyConfigOptions` value
available to consumers.
Change-Id: I88cf53d38faac8472c556aee55c13d0acbd1e5db
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r-- | src/libstore/globals.cc | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 6cfa3ffac..ab461e739 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -116,14 +116,15 @@ 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. */ @@ -131,14 +132,13 @@ void loadConfFile() auto files = settings.nixUserConfFiles; for (auto file = files.rbegin(); file != files.rend(); file++) { - applyConfigFile(*file); + applyConfigFile(ApplyConfigOptions{.path = *file}); } 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() @@ -264,7 +264,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; @@ -307,7 +307,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 { @@ -315,15 +315,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); } |