From 0acd783190418af514b363685e010195ea7260bc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 20 Feb 2024 15:22:15 +0100 Subject: [PATCH] Don't send settings that depend on disabled experimental features to the daemon This fixes warnings like warning: Ignoring setting 'auto-allocate-uids' because experimental feature 'auto-allocate-uids' is not enabled warning: Ignoring setting 'impure-env' because experimental feature 'configurable-impure-env' is not enabled when using the daemon and the user didn't actually set those settings. Note: this also hides those settings from `nix config show`, but that seems a good thing. --- src/libutil/config-impl.hh | 2 +- src/libutil/config.cc | 4 +++- tests/functional/experimental-features.sh | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libutil/config-impl.hh b/src/libutil/config-impl.hh index 9f69e8444..1da0cb638 100644 --- a/src/libutil/config-impl.hh +++ b/src/libutil/config-impl.hh @@ -4,7 +4,7 @@ * * Template implementations (as opposed to mere declarations). * - * This file is an exmample of the "impl.hh" pattern. See the + * This file is an example of the "impl.hh" pattern. See the * contributing guide. * * One only needs to include this when one is declaring a diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 37f5b50c7..617c2ec89 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -84,7 +84,9 @@ void AbstractConfig::reapplyUnknownSettings() void Config::getSettings(std::map & res, bool overriddenOnly) { for (const auto & opt : _settings) - if (!opt.second.isAlias && (!overriddenOnly || opt.second.setting->overridden)) + if (!opt.second.isAlias + && (!overriddenOnly || opt.second.setting->overridden) + && experimentalFeatureSettings.isEnabled(opt.second.setting->experimentalFeature)) res.emplace(opt.first, SettingInfo{opt.second.setting->to_string(), opt.second.setting->description}); } diff --git a/tests/functional/experimental-features.sh b/tests/functional/experimental-features.sh index 9ee4a53d4..12112b293 100644 --- a/tests/functional/experimental-features.sh +++ b/tests/functional/experimental-features.sh @@ -31,17 +31,19 @@ source common.sh NIX_CONFIG=' experimental-features = nix-command accept-flake-config = true -' nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr -grepQuiet "false" $TEST_ROOT/stdout +' expect 1 nix config show accept-flake-config 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 # 'flakes' experimental-feature is disabled after, ignore and warn NIX_CONFIG=' accept-flake-config = true experimental-features = nix-command -' nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr -grepQuiet "false" $TEST_ROOT/stdout +' expect 1 nix config show accept-flake-config 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 # 'flakes' experimental-feature is enabled before, process NIX_CONFIG='