forked from lix-project/lix
Mark experimental features on settings
We hide them in various ways if the experimental feature isn't enabled. To do this, we had to move the experimental features list out of libnixstore, because the setting machinary itself depends on it. To do that, we made a new `ExperimentalFeatureSettings`.
This commit is contained in:
parent
296831f641
commit
aa663b7e89
|
@ -75,21 +75,25 @@ struct FetchSettings : public Config
|
||||||
Path or URI of the global flake registry.
|
Path or URI of the global flake registry.
|
||||||
|
|
||||||
When empty, disables the global flake registry.
|
When empty, disables the global flake registry.
|
||||||
)"};
|
)",
|
||||||
|
{}, true, Xp::Flakes};
|
||||||
|
|
||||||
|
|
||||||
Setting<bool> useRegistries{this, true, "use-registries",
|
Setting<bool> useRegistries{this, true, "use-registries",
|
||||||
"Whether to use flake registries to resolve flake references."};
|
"Whether to use flake registries to resolve flake references.",
|
||||||
|
{}, true, Xp::Flakes};
|
||||||
|
|
||||||
Setting<bool> acceptFlakeConfig{this, false, "accept-flake-config",
|
Setting<bool> acceptFlakeConfig{this, false, "accept-flake-config",
|
||||||
"Whether to accept nix configuration from a flake without prompting."};
|
"Whether to accept nix configuration from a flake without prompting.",
|
||||||
|
{}, true, Xp::Flakes};
|
||||||
|
|
||||||
Setting<std::string> commitLockFileSummary{
|
Setting<std::string> commitLockFileSummary{
|
||||||
this, "", "commit-lockfile-summary",
|
this, "", "commit-lockfile-summary",
|
||||||
R"(
|
R"(
|
||||||
The commit summary to use when committing changed flake lock files. If
|
The commit summary to use when committing changed flake lock files. If
|
||||||
empty, the summary is generated based on the action performed.
|
empty, the summary is generated based on the action performed.
|
||||||
)"};
|
)",
|
||||||
|
{}, true, Xp::Flakes};
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: don't use a global variable.
|
// FIXME: don't use a global variable.
|
||||||
|
|
|
@ -70,10 +70,17 @@ void AbstractConfig::reapplyUnknownSettings()
|
||||||
set(s.first, s.second);
|
set(s.first, s.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whether we should process the option. Excludes aliases, which are handled elsewhere, and disabled features.
|
||||||
|
static bool applicable(const Config::SettingData & sd)
|
||||||
|
{
|
||||||
|
return !sd.isAlias
|
||||||
|
&& experimentalFeatureSettings.isEnabled(sd.setting->experimentalFeature);
|
||||||
|
}
|
||||||
|
|
||||||
void Config::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
|
void Config::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
|
||||||
{
|
{
|
||||||
for (auto & opt : _settings)
|
for (auto & opt : _settings)
|
||||||
if (!opt.second.isAlias && (!overriddenOnly || opt.second.setting->overridden))
|
if (applicable(opt.second) && (!overriddenOnly || opt.second.setting->overridden))
|
||||||
res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description});
|
res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,9 +154,8 @@ nlohmann::json Config::toJSON()
|
||||||
{
|
{
|
||||||
auto res = nlohmann::json::object();
|
auto res = nlohmann::json::object();
|
||||||
for (auto & s : _settings)
|
for (auto & s : _settings)
|
||||||
if (!s.second.isAlias) {
|
if (applicable(s.second))
|
||||||
res.emplace(s.first, s.second.setting->toJSON());
|
res.emplace(s.first, s.second.setting->toJSON());
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,24 +163,27 @@ std::string Config::toKeyValue()
|
||||||
{
|
{
|
||||||
auto res = std::string();
|
auto res = std::string();
|
||||||
for (auto & s : _settings)
|
for (auto & s : _settings)
|
||||||
if (!s.second.isAlias) {
|
if (applicable(s.second))
|
||||||
res += fmt("%s = %s\n", s.first, s.second.setting->to_string());
|
res += fmt("%s = %s\n", s.first, s.second.setting->to_string());
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::convertToArgs(Args & args, const std::string & category)
|
void Config::convertToArgs(Args & args, const std::string & category)
|
||||||
{
|
{
|
||||||
for (auto & s : _settings)
|
for (auto & s : _settings)
|
||||||
if (!s.second.isAlias)
|
if (applicable(s.second))
|
||||||
s.second.setting->convertToArg(args, category);
|
s.second.setting->convertToArg(args, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractSetting::AbstractSetting(
|
AbstractSetting::AbstractSetting(
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & description,
|
const std::string & description,
|
||||||
const std::set<std::string> & aliases)
|
const std::set<std::string> & aliases,
|
||||||
: name(name), description(stripIndentation(description)), aliases(aliases)
|
std::optional<ExperimentalFeature> experimentalFeature)
|
||||||
|
: name(name)
|
||||||
|
, description(stripIndentation(description))
|
||||||
|
, aliases(aliases)
|
||||||
|
, experimentalFeature(experimentalFeature)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,12 +195,15 @@ public:
|
||||||
|
|
||||||
bool overridden = false;
|
bool overridden = false;
|
||||||
|
|
||||||
|
std::optional<ExperimentalFeature> experimentalFeature;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AbstractSetting(
|
AbstractSetting(
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & description,
|
const std::string & description,
|
||||||
const std::set<std::string> & aliases);
|
const std::set<std::string> & aliases,
|
||||||
|
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt);
|
||||||
|
|
||||||
virtual ~AbstractSetting()
|
virtual ~AbstractSetting()
|
||||||
{
|
{
|
||||||
|
@ -241,8 +244,9 @@ public:
|
||||||
const bool documentDefault,
|
const bool documentDefault,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & description,
|
const std::string & description,
|
||||||
const std::set<std::string> & aliases = {})
|
const std::set<std::string> & aliases = {},
|
||||||
: AbstractSetting(name, description, aliases)
|
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
|
||||||
|
: AbstractSetting(name, description, aliases, experimentalFeature)
|
||||||
, value(def)
|
, value(def)
|
||||||
, defaultValue(def)
|
, defaultValue(def)
|
||||||
, documentDefault(documentDefault)
|
, documentDefault(documentDefault)
|
||||||
|
@ -297,8 +301,9 @@ public:
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
const std::string & description,
|
const std::string & description,
|
||||||
const std::set<std::string> & aliases = {},
|
const std::set<std::string> & aliases = {},
|
||||||
const bool documentDefault = true)
|
const bool documentDefault = true,
|
||||||
: BaseSetting<T>(def, documentDefault, name, description, aliases)
|
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
|
||||||
|
: BaseSetting<T>(def, documentDefault, name, description, aliases, experimentalFeature)
|
||||||
{
|
{
|
||||||
options->addSetting(this);
|
options->addSetting(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue