Skip to content

Commit

Permalink
Merge pull request #8203 from NixOS/backport-8201-to-2.15-maintenance
Browse files Browse the repository at this point in the history
[Backport 2.15-maintenance] Do not gate or hide experimental settings
  • Loading branch information
Ericson2314 committed Apr 11, 2023
2 parents d2932ad + 9af0a0e commit 8340e26
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
16 changes: 3 additions & 13 deletions src/libutil/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,10 @@ void AbstractConfig::reapplyUnknownSettings()
set(s.first, s.second);
}

// Whether we should process the option. Excludes aliases, which are handled elsewhere, and disabled features.
static bool applicable(const Config::SettingData & sd)
{
return !sd.isAlias
&& experimentalFeatureSettings.isEnabled(sd.setting->experimentalFeature);
}

void Config::getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly)
{
for (auto & opt : _settings)
if (applicable(opt.second) && (!overriddenOnly || opt.second.setting->overridden))
if (!opt.second.isAlias && (!overriddenOnly || opt.second.setting->overridden))
res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description});
}

Expand Down Expand Up @@ -154,7 +147,7 @@ nlohmann::json Config::toJSON()
{
auto res = nlohmann::json::object();
for (auto & s : _settings)
if (applicable(s.second))
if (!s.second.isAlias)
res.emplace(s.first, s.second.setting->toJSON());
return res;
}
Expand All @@ -163,17 +156,14 @@ std::string Config::toKeyValue()
{
auto res = std::string();
for (auto & s : _settings)
if (applicable(s.second))
if (s.second.isAlias)
res += fmt("%s = %s\n", s.first, s.second.setting->to_string());
return res;
}

void Config::convertToArgs(Args & args, const std::string & category)
{
for (auto & s : _settings) {
/* We do include args for settings gated on disabled
experimental-features. The args themselves however will also be
gated on any experimental feature the underlying setting is. */
if (!s.second.isAlias)
s.second.setting->convertToArg(args, category);
}
Expand Down
42 changes: 22 additions & 20 deletions tests/experimental-features.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
source common.sh

# Without flakes, flake options should not show up
# With flakes, flake options should show up

function both_ways {
nix --experimental-features 'nix-command' "$@" | grepQuietInverse flake
nix --experimental-features 'nix-command flakes' "$@" | grepQuiet flake

# Also, the order should not matter
nix "$@" --experimental-features 'nix-command' | grepQuietInverse flake
nix "$@" --experimental-features 'nix-command flakes' | grepQuiet flake
}

# Simple case, the configuration effects the running command
both_ways show-config

# Skipping for now, because we actually *do* want these to show up in
# the manual, just be marked experimental. Will reenable once the manual
# generation takes advantage of the JSON metadata on this.

# both_ways store gc --help
# Skipping these two for now, because we actually *do* want flags and
# config settings to always show up in the manual, just be marked
# experimental. Will reenable once the manual generation takes advantage
# of the JSON metadata on this.
#
# # Without flakes, flake options should not show up
# # With flakes, flake options should show up
#
# function grep_both_ways {
# nix --experimental-features 'nix-command' "$@" | grepQuietInverse flake
# nix --experimental-features 'nix-command flakes' "$@" | grepQuiet flake
#
# # Also, the order should not matter
# nix "$@" --experimental-features 'nix-command' | grepQuietInverse flake
# nix "$@" --experimental-features 'nix-command flakes' | grepQuiet flake
# }
#
# # Simple case, the configuration effects the running command
# grep_both_ways show-config
#
# # Medium case, the configuration effects --help
# grep_both_ways store gc --help

expect 1 nix --experimental-features 'nix-command' show-config --flake-registry 'https://no'
nix --experimental-features 'nix-command flakes' show-config --flake-registry 'https://no'
Expand Down

0 comments on commit 8340e26

Please sign in to comment.