Add experimental-features setting

Experimental features are now opt-in. There are currently two
experimental features: "nix-command" (which enables the "nix"
command), and "flakes" (which enables support for flakes). This will
allow us to merge experimental features more quickly, without
committing to supporting them indefinitely.

Typical usage:

$ nix build --experimental-features 'nix-command flakes' nixpkgs#hello
This commit is contained in:
Eelco Dolstra 2019-10-16 17:45:09 +02:00
parent a56036fa87
commit 8e478c2341
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 17 additions and 0 deletions

View file

@ -433,6 +433,8 @@ static std::pair<Flake, LockedInput> updateLocks(
and optionally write it to file, it the flake is writable. */ and optionally write it to file, it the flake is writable. */
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile) ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile)
{ {
settings.requireExperimentalFeature("flakes");
auto flake = getFlake(state, topRef, auto flake = getFlake(state, topRef,
allowedToUseRegistries(handleLockFile, true)); allowedToUseRegistries(handleLockFile, true));

View file

@ -105,6 +105,13 @@ StringSet Settings::getDefaultSystemFeatures()
return features; return features;
} }
void Settings::requireExperimentalFeature(const std::string & name)
{
auto & f = experimentalFeatures.get();
if (std::find(f.begin(), f.end(), name) == f.end())
throw Error("experimental Nix feature '%s' is disabled", name);
}
const string nixVersion = PACKAGE_VERSION; const string nixVersion = PACKAGE_VERSION;
template<> void BaseSetting<SandboxMode>::set(const std::string & str) template<> void BaseSetting<SandboxMode>::set(const std::string & str)

View file

@ -356,6 +356,11 @@ public:
Setting<std::string> githubAccessToken{this, "", "github-acces-token", Setting<std::string> githubAccessToken{this, "", "github-acces-token",
"GitHub access token to get access to GitHub data through the GitHub API for github:<..> flakes."}; "GitHub access token to get access to GitHub data through the GitHub API for github:<..> flakes."};
Setting<Strings> experimentalFeatures{this, {}, "experimental-features",
"Experimental Nix features to enable."};
void requireExperimentalFeature(const std::string & name);
}; };

View file

@ -149,6 +149,8 @@ void mainWrapped(int argc, char * * argv)
args.parseCmdline(argvToStrings(argc, argv)); args.parseCmdline(argvToStrings(argc, argv));
settings.requireExperimentalFeature("nix-command");
initPlugins(); initPlugins();
if (!args.command) args.showHelpAndExit(); if (!args.command) args.showHelpAndExit();

View file

@ -17,6 +17,7 @@ cat > "$NIX_CONF_DIR"/nix.conf <<EOF
build-users-group = build-users-group =
keep-derivations = false keep-derivations = false
sandbox = false sandbox = false
experimental-features = nix-command flakes
include nix.conf.extra include nix.conf.extra
EOF EOF