mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 13:06:01 +01:00
Move enabled experimental feature to libutil struct
This is needed in subsequent commits to allow the settings and CLI args infrastructure itself to read this setting.
This commit is contained in:
parent
1b6c96bbcb
commit
296831f641
28 changed files with 113 additions and 70 deletions
|
|
@ -444,4 +444,30 @@ GlobalConfig::Register::Register(Config * config)
|
|||
configRegistrations->emplace_back(config);
|
||||
}
|
||||
|
||||
ExperimentalFeatureSettings experimentalFeatureSettings;
|
||||
|
||||
static GlobalConfig::Register rSettings(&experimentalFeatureSettings);
|
||||
|
||||
bool ExperimentalFeatureSettings::isEnabled(const ExperimentalFeature & feature) const
|
||||
{
|
||||
auto & f = experimentalFeatures.get();
|
||||
return std::find(f.begin(), f.end(), feature) != f.end();
|
||||
}
|
||||
|
||||
void ExperimentalFeatureSettings::require(const ExperimentalFeature & feature) const
|
||||
{
|
||||
if (!isEnabled(feature))
|
||||
throw MissingExperimentalFeature(feature);
|
||||
}
|
||||
|
||||
bool ExperimentalFeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const
|
||||
{
|
||||
return !feature || isEnabled(*feature);
|
||||
}
|
||||
|
||||
void ExperimentalFeatureSettings::require(const std::optional<ExperimentalFeature> & feature) const
|
||||
{
|
||||
if (feature) require(*feature);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "types.hh"
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
#pragma once
|
||||
#include "types.hh"
|
||||
#include "experimental-features.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -357,4 +358,37 @@ struct GlobalConfig : public AbstractConfig
|
|||
|
||||
extern GlobalConfig globalConfig;
|
||||
|
||||
|
||||
struct ExperimentalFeatureSettings : Config {
|
||||
|
||||
Setting<std::set<ExperimentalFeature>> experimentalFeatures{this, {}, "experimental-features",
|
||||
"Experimental Nix features to enable."};
|
||||
|
||||
/**
|
||||
* Check whether the given experimental feature is enabled.
|
||||
*/
|
||||
bool isEnabled(const ExperimentalFeature &) const;
|
||||
|
||||
/**
|
||||
* Require an experimental feature be enabled, throwing an error if it is
|
||||
* not.
|
||||
*/
|
||||
void require(const ExperimentalFeature &) const;
|
||||
|
||||
/**
|
||||
* `std::nullopt` pointer means no feature, which means there is nothing that could be
|
||||
* disabled, and so the function returns true in that case.
|
||||
*/
|
||||
bool isEnabled(const std::optional<ExperimentalFeature> &) const;
|
||||
|
||||
/**
|
||||
* `std::nullopt` pointer means no feature, which means there is nothing that could be
|
||||
* disabled, and so the function does nothing in that case.
|
||||
*/
|
||||
void require(const std::optional<ExperimentalFeature> &) const;
|
||||
};
|
||||
|
||||
// FIXME: don't use a global variable.
|
||||
extern ExperimentalFeatureSettings experimentalFeatureSettings;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue