aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/globals.cc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-10-25 15:53:01 +0200
committerregnat <rg@regnat.ovh>2021-10-26 07:02:31 +0200
commitaf99941279b80c962ec9cae3e5fa32976a3f5744 (patch)
tree034ffb01457354b07e9b6dac02892e1b5d8fca09 /src/libstore/globals.cc
parent4a2b7cc68c7d11ec126bc412ffea838e629345af (diff)
Make experimental-features a proper type
Rather than having them plain strings scattered through the whole codebase, create an enum containing all the known experimental features. This means that - Nix can now `warn` when an unkwown experimental feature is passed (making it much nicer to spot typos and spot deprecated features) - It’s now easy to remove a feature altogether (once the feature isn’t experimental anymore or is dropped) by just removing the field for the enum and letting the compiler point us to all the now invalid usages of it.
Diffstat (limited to 'src/libstore/globals.cc')
-rw-r--r--src/libstore/globals.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 4903d0922..9f1a88130 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -160,21 +160,16 @@ StringSet Settings::getDefaultExtraPlatforms()
return extraPlatforms;
}
-bool Settings::isExperimentalFeatureEnabled(const std::string & name)
+bool Settings::isExperimentalFeatureEnabled(const ExperimentalFeature & feature)
{
auto & f = experimentalFeatures.get();
- return std::find(f.begin(), f.end(), name) != f.end();
+ return std::find(f.begin(), f.end(), feature) != f.end();
}
-MissingExperimentalFeature::MissingExperimentalFeature(std::string feature)
- : Error("experimental Nix feature '%1%' is disabled; use '--extra-experimental-features %1%' to override", feature)
- , missingFeature(feature)
- {}
-
-void Settings::requireExperimentalFeature(const std::string & name)
+void Settings::requireExperimentalFeature(const ExperimentalFeature & feature)
{
- if (!isExperimentalFeatureEnabled(name))
- throw MissingExperimentalFeature(name);
+ if (!isExperimentalFeatureEnabled(feature))
+ throw MissingExperimentalFeature(feature);
}
bool Settings::isWSL1()