forked from NixOS/nix
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfig-global.cc
More file actions
80 lines (63 loc) · 1.96 KB
/
config-global.cc
File metadata and controls
80 lines (63 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "nix/util/config-global.hh"
#include <nlohmann/json.hpp>
namespace nix {
GlobalConfig::ConfigRegistrations & GlobalConfig::configRegistrations()
{
static GlobalConfig::ConfigRegistrations configRegistrations;
return configRegistrations;
}
bool GlobalConfig::set(const std::string & name, const std::string & value)
{
for (auto & config : configRegistrations())
if (config->set(name, value))
return true;
unknownSettings.emplace(name, value);
return false;
}
void GlobalConfig::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly) const
{
for (auto & config : configRegistrations())
config->getSettings(res, overriddenOnly);
}
void GlobalConfig::resetOverridden()
{
for (auto & config : configRegistrations())
config->resetOverridden();
}
nlohmann::json GlobalConfig::toJSON()
{
auto res = nlohmann::json::object();
for (const auto & config : configRegistrations())
res.update(config->toJSON());
return res;
}
std::string GlobalConfig::toKeyValue()
{
std::string res;
std::map<std::string, Config::SettingInfo> settings;
globalConfig.getSettings(settings);
for (const auto & s : settings)
res += fmt("%s = %s\n", s.first, s.second.value);
return res;
}
void GlobalConfig::convertToArgs(Args & args, const std::string & category)
{
for (auto & config : configRegistrations())
config->convertToArgs(args, category);
}
GlobalConfig globalConfig;
GlobalConfig::Register::Register(Config * config)
{
auto regs = configRegistrations();
if (std::find(regs.begin(), regs.end(), config) == regs.end()) {
configRegistrations().emplace_back(config);
}
}
GlobalConfig::Register::Register(Config * config, std::function<void()> && callback)
: Register(config)
{
callback();
}
ExperimentalFeatureSettings experimentalFeatureSettings;
static GlobalConfig::Register rSettings(&experimentalFeatureSettings);
} // namespace nix