Warn when experimental features are used

If you use an experimental feature not listed in the
'experimental-features' setting, you now get a warning rather than a
fatal error. This makes things like the 'nix' command a bit less
obnoxious.

However, if you set 'allow-experimental-features = false', it's still
a fatal error. This is primarily for CI systems where use of
experimental features in the daemon could go unnoticed.
This commit is contained in:
Eelco Dolstra 2020-06-24 23:09:12 +02:00
parent 3c50e84387
commit 131d063ea1
2 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include "util.hh"
#include "archive.hh"
#include "args.hh"
#include "sync.hh"
#include <algorithm>
#include <map>
@ -129,8 +130,14 @@ bool Settings::isExperimentalFeatureEnabled(const std::string & name)
void Settings::requireExperimentalFeature(const std::string & name)
{
if (!isExperimentalFeatureEnabled(name))
throw Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", name);
if (!isExperimentalFeatureEnabled(name)) {
if (allowExperimentalFeatures) {
static Sync<std::unordered_set<std::string>> warned;
if (warned.lock()->insert(name).second)
warn("feature '%s' is experimental", name);
} else
throw Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", name);
}
}
bool Settings::isWSL1()

View File

@ -357,6 +357,10 @@ public:
Setting<std::string> githubAccessToken{this, "", "github-access-token",
"GitHub access token to get access to GitHub data through the GitHub API for github:<..> flakes."};
Setting<bool> allowExperimentalFeatures{this, true, "allow-experimental-features",
"Whether the use of experimental features other than those listed in "
"the option 'experimental-features' gives a warning rather than fatal error."};
Setting<Strings> experimentalFeatures{this, {}, "experimental-features",
"Experimental Nix features to enable."};