Skip to content

Commit

Permalink
Warn when experimental features are used
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edolstra committed Jun 24, 2020
1 parent 3c50e84 commit 131d063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libstore/globals.cc
Expand Up @@ -2,6 +2,7 @@
#include "util.hh"
#include "archive.hh"
#include "args.hh"
#include "sync.hh"

#include <algorithm>
#include <map>
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/libstore/globals.hh
Expand Up @@ -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."};

Expand Down

0 comments on commit 131d063

Please sign in to comment.