1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 01:11:15 +02:00

Make the flakes experimental feature stable

This commit is contained in:
Graham Christensen 2023-10-29 21:50:35 +00:00 committed by Eelco Dolstra
parent 7747a501db
commit 590920eed2
27 changed files with 59 additions and 107 deletions

View file

@ -23,7 +23,7 @@ jobs:
with:
flakehub: true
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix --experimental-features 'nix-command flakes' flake check -L
- run: nix --experimental-features 'nix-command' flake check -L
vm_tests:
needs: tests

View file

@ -14,10 +14,9 @@ The following instructions assume you already have some version of Nix installed
## Building Nix with flakes
This section assumes you are using Nix with the [`flakes`] and [`nix-command`] experimental features enabled.
This section assumes you are using Nix with the experimental feature [`nix-command`] enabled.
See the [Building Nix](#building-nix) section for equivalent instructions using stable Nix interfaces.
[`flakes`]: @docroot@/contributing/experimental-features.md#xp-feature-flakes
[`nix-command`]: @docroot@/contributing/experimental-features.md#xp-nix-command
To build all dependencies and start a shell in which all environment variables are set up so that those dependencies can be found:

View file

@ -22,7 +22,6 @@ EvalSettings evalSettings {
{
"flake",
[](ref<Store> store, std::string_view rest) {
experimentalFeatureSettings.require(Xp::Flakes);
// FIXME `parseFlakeRef` should take a `std::string_view`.
auto flakeRef = parseFlakeRef(std::string { rest }, {}, true, false);
debug("fetching flake search path element '%s''", rest);
@ -229,7 +228,6 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas
}
else if (hasPrefix(s, "flake:")) {
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(std::string(s.substr(6)), {}, true, false);
auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first;
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));

View file

@ -394,9 +394,6 @@ void completeFlakeRefWithFragment(
void completeFlakeRef(AddCompletions & completions, ref<Store> store, std::string_view prefix)
{
if (!experimentalFeatureSettings.isEnabled(Xp::Flakes))
return;
if (prefix == "")
completions.add(".");

View file

@ -163,15 +163,11 @@ static void fetchTree(
}
input = fetchers::Input::fromAttrs(std::move(attrs));
} else {
if (!experimentalFeatureSettings.isEnabled(Xp::Flakes))
state.error<EvalError>(
"passing a string argument to 'fetchTree' requires the 'flakes' experimental feature"
).atPos(pos).debugThrow();
input = fetchers::Input::fromURL(url);
}
}
if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
if (!state.settings.pureEval && !input.isDirect())
input = lookupInRegistries(state.store, input).first;
if (state.settings.pureEval && !input.isLocked()) {
@ -383,7 +379,6 @@ static RegisterPrimOp primop_fetchTree({
- `"mercurial"`
*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references).
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/contributing/experimental-features.md#xp-feature-flakes) to be enabled.
> **Example**
>
@ -420,7 +415,6 @@ static RegisterPrimOp primop_fetchTree({
> ```
)",
.fun = prim_fetchTree,
.experimentalFeature = Xp::FetchTree,
});
static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v,

View file

@ -299,11 +299,6 @@ struct GitArchiveInputScheme : InputScheme
input.getNarHash().has_value());
}
std::optional<ExperimentalFeature> experimentalFeature() const override
{
return Xp::Flakes;
}
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
{
if (auto rev = input.getRev())

View file

@ -102,11 +102,6 @@ struct IndirectInputScheme : InputScheme
throw Error("indirect input '%s' cannot be fetched directly", input.to_string());
}
std::optional<ExperimentalFeature> experimentalFeature() const override
{
return Xp::Flakes;
}
bool isDirect(const Input & input) const override
{ return false; }
};

View file

@ -174,11 +174,6 @@ struct PathInputScheme : InputScheme
return std::nullopt;
}
}
std::optional<ExperimentalFeature> experimentalFeature() const override
{
return Xp::Flakes;
}
};
static auto rPathInputScheme = OnStartup([] { registerInputScheme(std::make_unique<PathInputScheme>()); });

View file

@ -156,7 +156,7 @@ struct RegistrySettings : Config
When empty, disables the global flake registry.
)",
{}, true, Xp::Flakes};
{}, true};
};
RegistrySettings registrySettings;

View file

@ -22,8 +22,7 @@ struct FlakeSettings : public Config
"use-registries",
"Whether to use flake registries to resolve flake references.",
{},
true,
Xp::Flakes};
true};
Setting<bool> acceptFlakeConfig{
this,
@ -31,8 +30,7 @@ struct FlakeSettings : public Config
"accept-flake-config",
"Whether to accept nix configuration from a flake without prompting.",
{},
true,
Xp::Flakes};
true};
Setting<std::string> commitLockFileSummary{
this,
@ -43,8 +41,7 @@ struct FlakeSettings : public Config
empty, the summary is generated based on the action performed.
)",
{"commit-lockfile-summary"},
true,
Xp::Flakes};
true};
};
// TODO: don't use a global variable.

View file

@ -343,8 +343,6 @@ LockedFlake lockFlake(
const FlakeRef & topRef,
const LockFlags & lockFlags)
{
experimentalFeatureSettings.require(Xp::Flakes);
FlakeCache flakeCache;
auto useRegistries = lockFlags.useRegistries.value_or(flakeSettings.useRegistries);
@ -744,8 +742,6 @@ void callFlake(EvalState & state,
const LockedFlake & lockedFlake,
Value & vRes)
{
experimentalFeatureSettings.require(Xp::Flakes);
auto [lockFileStr, keyMap] = lockedFlake.lockFile.to_string();
auto overrides = state.buildBindings(lockedFlake.nodePaths.size());
@ -837,7 +833,6 @@ static RegisterPrimOp r2({
```
)",
.fun = prim_getFlake,
.experimentalFeature = Xp::Flakes,
});
static void prim_parseFlakeRef(
@ -881,7 +876,6 @@ static RegisterPrimOp r3({
```
)",
.fun = prim_parseFlakeRef,
.experimentalFeature = Xp::Flakes,
});
@ -938,7 +932,6 @@ static RegisterPrimOp r4({
```
)",
.fun = prim_flakeRefToString,
.experimentalFeature = Xp::Flakes,
});
}

View file

@ -341,11 +341,9 @@ template<> std::set<ExperimentalFeature> BaseSetting<std::set<ExperimentalFeatur
{
std::set<ExperimentalFeature> res;
for (auto & s : tokenizeString<StringSet>(str)) {
if (auto thisXpFeature = parseExperimentalFeature(s); thisXpFeature) {
if (auto thisXpFeature = parseExperimentalFeature(s); thisXpFeature)
res.insert(thisXpFeature.value());
if (thisXpFeature.value() == Xp::Flakes)
res.insert(Xp::FetchTree);
} else
else
warn("unknown experimental feature '%s'", s);
}
return res;

View file

@ -386,7 +386,7 @@ struct ExperimentalFeatureSettings : Config {
Example:
```
experimental-features = nix-command flakes
experimental-features = nix-command
```
The following experimental features are available:

View file

@ -74,8 +74,9 @@ constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails
.tag = Xp::Flakes,
.name = "flakes",
.description = R"(
Enable flakes. See the manual entry for [`nix
flake`](@docroot@/command-ref/new-cli/nix3-flake.md) for details.
*Enabled for Determinate Nix Installer users since 2.19*
See the manual entry for [`nix flake`](@docroot@/command-ref/new-cli/nix3-flake.md) for details.
)",
.trackingUrl = "https://github.com/NixOS/nix/milestone/27",
},
@ -83,6 +84,8 @@ constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails
.tag = Xp::FetchTree,
.name = "fetch-tree",
.description = R"(
*Enabled for Determinate Nix Installer users since 2.24*
Enable the use of the [`fetchTree`](@docroot@/language/builtins.md#builtins-fetchTree) built-in function in the Nix language.
`fetchTree` exposes a generic interface for fetching remote file system trees from different types of remote sources.

View file

@ -1462,12 +1462,6 @@ struct CmdFlake : NixMultiCommand
#include "flake.md"
;
}
void run() override
{
experimentalFeatureSettings.require(Xp::Flakes);
NixMultiCommand::run();
}
};
static auto rCmdFlake = registerCommand<CmdFlake>("flake");

View file

@ -412,7 +412,6 @@ void mainWrapped(int argc, char * * argv)
if (argc == 2 && std::string(argv[1]) == "__dump-language") {
experimentalFeatureSettings.experimentalFeatures = {
Xp::Flakes,
Xp::FetchClosure,
Xp::DynamicDerivations,
Xp::FetchTree,

View file

@ -69,11 +69,9 @@ That is, Nix will operate on the default flake output attribute of the flake in
### Flake output attribute
> **Warning** \
> Flake output attribute installables depend on both the
> [`flakes`](@docroot@/contributing/experimental-features.md#xp-feature-flakes)
> and
> Flake output attribute installables depend on the
> [`nix-command`](@docroot@/contributing/experimental-features.md#xp-feature-nix-command)
> experimental features, and subject to change without notice.
> experimental feature, and subject to change without notice.
Example: `nixpkgs#hello`

View file

@ -36,7 +36,7 @@ R""(
Loading Installable ''...
Added 1 variables.
# nix repl --extra-experimental-features 'flakes' nixpkgs
# nix repl nixpkgs
Loading Installable 'flake:nixpkgs#'...
Added 5 variables.

View file

@ -4,7 +4,7 @@ source common.sh
requireDaemonNewerThan "2.4pre20210626"
enableFeatures "ca-derivations nix-command flakes"
enableFeatures "ca-derivations nix-command"
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..

View file

@ -12,7 +12,7 @@ if isTestOnNixOS; then
! test -e "$test_nix_conf"
cat > "$test_nix_conf_dir/nix.conf" <<EOF
# TODO: this is not needed for all tests and prevents stable commands from be tested in isolation
experimental-features = nix-command flakes
experimental-features = nix-command
flake-registry = $TEST_ROOT/registry.json
show-trace = true
EOF
@ -58,7 +58,6 @@ EOF
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
fsync-metadata = false
extra-experimental-features = flakes
!include nix.conf.extra.not-there
EOF

View file

@ -59,13 +59,11 @@ var=$(nix config show | grep '^experimental-features =' | cut -d '=' -f 2 | xarg
# Test that it's possible to load config from the environment
prev=$(nix config show | grep '^cores' | cut -d '=' -f 2 | xargs)
export NIX_CONFIG="cores = 4242"$'\n'"experimental-features = nix-command flakes"
export NIX_CONFIG="cores = 4242"$'\n'"experimental-features = nix-command"
exp_cores=$(nix config show | grep '^cores' | cut -d '=' -f 2 | xargs)
exp_features=$(nix config show | grep '^experimental-features' | cut -d '=' -f 2 | xargs)
[[ $prev != $exp_cores ]]
[[ $exp_cores == "4242" ]]
# flakes implies fetch-tree
[[ $exp_features == "fetch-tree flakes nix-command" ]]
# Test that it's possible to retrieve a single setting's value
val=$(nix config show | grep '^warn-dirty' | cut -d '=' -f 2 | xargs)

View file

@ -12,11 +12,11 @@ source common.sh
#
# function grep_both_ways {
# nix --experimental-features 'nix-command' "$@" | grepQuietInverse flake
# nix --experimental-features 'nix-command flakes' "$@" | grepQuiet flake
# nix --experimental-features 'nix-command' "$@" | grepQuiet flake
#
# # Also, the order should not matter
# nix "$@" --experimental-features 'nix-command' | grepQuietInverse flake
# nix "$@" --experimental-features 'nix-command flakes' | grepQuiet flake
# nix "$@" --experimental-features 'nix-command' | grepQuiet flake
# }
#
# # Simple case, the configuration effects the running command
@ -29,50 +29,50 @@ source common.sh
# with a warning if the experimental feature is not enabled. The order of the
# `setting = value` lines in the configuration should not matter.
# 'flakes' experimental-feature is disabled before, ignore and warn
NIX_CONFIG='
xpFeature=auto-allocate-uids
gatedSetting=auto-allocate-uids
# Experimental feature is disabled before, ignore and warn.
NIX_CONFIG="
experimental-features = nix-command
accept-flake-config = true
' expect 1 nix config show accept-flake-config 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
$gatedSetting = true
" expect 1 nix config show $gatedSetting 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
[[ $(cat "$TEST_ROOT/stdout") = '' ]]
grepQuiet "Ignoring setting 'accept-flake-config' because experimental feature 'flakes' is not enabled" "$TEST_ROOT/stderr"
grepQuiet "error: could not find setting 'accept-flake-config'" "$TEST_ROOT/stderr"
grepQuiet "error: could not find setting '$gatedSetting'" "$TEST_ROOT/stderr"
# 'flakes' experimental-feature is disabled after, ignore and warn
NIX_CONFIG='
accept-flake-config = true
# Experimental feature is disabled after, ignore and warn.
NIX_CONFIG="
$gatedSetting = true
experimental-features = nix-command
' expect 1 nix config show accept-flake-config 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
" expect 1 nix config show $gatedSetting 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
[[ $(cat "$TEST_ROOT/stdout") = '' ]]
grepQuiet "Ignoring setting 'accept-flake-config' because experimental feature 'flakes' is not enabled" "$TEST_ROOT/stderr"
grepQuiet "error: could not find setting 'accept-flake-config'" "$TEST_ROOT/stderr"
grepQuiet "error: could not find setting '$gatedSetting'" "$TEST_ROOT/stderr"
# 'flakes' experimental-feature is enabled before, process
NIX_CONFIG='
experimental-features = nix-command flakes
accept-flake-config = true
' nix config show accept-flake-config 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
# Experimental feature is enabled before, process.
NIX_CONFIG="
experimental-features = nix-command $xpFeature
$gatedSetting = true
" nix config show $gatedSetting 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
grepQuiet "true" "$TEST_ROOT/stdout"
grepQuietInverse "Ignoring setting 'accept-flake-config'" "$TEST_ROOT/stderr"
# 'flakes' experimental-feature is enabled after, process
NIX_CONFIG='
accept-flake-config = true
experimental-features = nix-command flakes
' nix config show accept-flake-config 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
# Experimental feature is enabled after, process.
NIX_CONFIG="
$gatedSetting = true
experimental-features = nix-command $xpFeature
" nix config show $gatedSetting 1>"$TEST_ROOT"/stdout 2>"$TEST_ROOT"/stderr
grepQuiet "true" "$TEST_ROOT/stdout"
grepQuietInverse "Ignoring setting 'accept-flake-config'" "$TEST_ROOT/stderr"
grepQuietInverse "Ignoring setting '$gatedSetting'" "$TEST_ROOT/stderr"
function exit_code_both_ways {
expect 1 nix --experimental-features 'nix-command' "$@" 1>/dev/null
nix --experimental-features 'nix-command flakes' "$@" 1>/dev/null
expect 1 nix --experimental-features 'nix-command ' "$@" 1>/dev/null
nix --experimental-features "nix-command $xpFeature" "$@" 1>/dev/null
# Also, the order should not matter
expect 1 nix "$@" --experimental-features 'nix-command' 1>/dev/null
nix "$@" --experimental-features 'nix-command flakes' 1>/dev/null
nix "$@" --experimental-features "nix-command $xpFeature" 1>/dev/null
}
exit_code_both_ways show-config --flake-registry 'https://no'
exit_code_both_ways config show --auto-allocate-uids
# Double check these are stable
nix --experimental-features '' --help 1>/dev/null

View file

@ -140,9 +140,9 @@ EOF
testReplResponse '
foo + baz
' "3" \
./flake ./flake\#bar --experimental-features 'flakes'
./flake ./flake\#bar
# Test the `:reload` mechansim with flakes:
# Test the `:reload` mechanism with flakes:
# - Eval `./flake#changingThing`
# - Modify the flake
# - Re-eval it
@ -153,7 +153,7 @@ sleep 1 # Leave the repl the time to eval 'foo'
sed -i 's/beforeChange/afterChange/' flake/flake.nix
echo ":reload"
echo "changingThing"
) | nix repl ./flake --experimental-features 'flakes')
) | nix repl ./flake)
echo "$replResult" | grepQuiet -s beforeChange
echo "$replResult" | grepQuiet -s afterChange

View file

@ -143,7 +143,7 @@ in
virtualisation.additionalPaths = [ pkgs.hello pkgs.fuse ];
virtualisation.memorySize = 4096;
nix.settings.substituters = lib.mkForce [ ];
nix.extraOptions = "experimental-features = nix-command flakes";
nix.extraOptions = "experimental-features = nix-command";
networking.hosts.${(builtins.head nodes.github.networking.interfaces.eth1.ipv4.addresses).address} =
[ "channels.nixos.org" "api.github.com" "github.com" ];
security.pki.certificateFiles = [ "${cert}/ca.crt" ];

View file

@ -104,7 +104,7 @@ in
virtualisation.memorySize = 4096;
nix.settings.substituters = lib.mkForce [ ];
nix.extraOptions = ''
experimental-features = nix-command flakes
experimental-features = nix-command
flake-registry = https://git.sr.ht/~NixOS/flake-registry/blob/master/flake-registry.json
'';
environment.systemPackages = [ pkgs.jq ];

View file

@ -51,7 +51,7 @@ in
virtualisation.additionalPaths = [ pkgs.hello pkgs.fuse ];
virtualisation.memorySize = 4096;
nix.settings.substituters = lib.mkForce [ ];
nix.extraOptions = "experimental-features = nix-command flakes";
nix.extraOptions = "experimental-features = nix-command";
};
};

View file

@ -191,7 +191,7 @@ namespace nix {
"description",
{},
true,
Xp::Flakes,
Xp::CaDerivations,
};
setting.assign("value");
@ -203,7 +203,7 @@ namespace nix {
"description": "description\n",
"documentDefault": true,
"value": "value",
"experimentalFeature": "flakes"
"experimentalFeature": "ca-derivations"
}
})#"_json);
}