mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 14:22:29 +00:00
Allow loading config files into other config objects
This gives us some hope of moving away from global variables.
This commit is contained in:
parent
b46e13840b
commit
cb0c868da4
@ -124,12 +124,12 @@ Settings::Settings()
|
||||
};
|
||||
}
|
||||
|
||||
void loadConfFile()
|
||||
void loadConfFile(AbstractConfig & config)
|
||||
{
|
||||
auto applyConfigFile = [&](const Path & path) {
|
||||
try {
|
||||
std::string contents = readFile(path);
|
||||
globalConfig.applyConfig(contents, path);
|
||||
config.applyConfig(contents, path);
|
||||
} catch (SystemError &) { }
|
||||
};
|
||||
|
||||
@ -137,7 +137,7 @@ void loadConfFile()
|
||||
|
||||
/* We only want to send overrides to the daemon, i.e. stuff from
|
||||
~/.nix/nix.conf or the command line. */
|
||||
globalConfig.resetOverridden();
|
||||
config.resetOverridden();
|
||||
|
||||
auto files = settings.nixUserConfFiles;
|
||||
for (auto file = files.rbegin(); file != files.rend(); file++) {
|
||||
@ -146,7 +146,7 @@ void loadConfFile()
|
||||
|
||||
auto nixConfEnv = getEnv("NIX_CONFIG");
|
||||
if (nixConfEnv.has_value()) {
|
||||
globalConfig.applyConfig(nixConfEnv.value(), "NIX_CONFIG");
|
||||
config.applyConfig(nixConfEnv.value(), "NIX_CONFIG");
|
||||
}
|
||||
|
||||
}
|
||||
@ -438,7 +438,7 @@ void initLibStore(bool loadConfig) {
|
||||
initLibUtil();
|
||||
|
||||
if (loadConfig)
|
||||
loadConfFile();
|
||||
loadConfFile(globalConfig);
|
||||
|
||||
preloadNSS();
|
||||
|
||||
|
@ -1284,7 +1284,13 @@ extern Settings settings;
|
||||
*/
|
||||
void initPlugins();
|
||||
|
||||
void loadConfFile();
|
||||
/**
|
||||
* Load the configuration (from `nix.conf`, `NIX_CONFIG`, etc.) into the
|
||||
* given configuration object.
|
||||
*
|
||||
* Usually called with `globalConfig`.
|
||||
*/
|
||||
void loadConfFile(AbstractConfig & config);
|
||||
|
||||
// Used by the Settings constructor
|
||||
std::vector<Path> getUserConfigFiles();
|
||||
|
Loading…
Reference in New Issue
Block a user