diff --git a/modules/lib/deprecations.nix b/modules/lib/deprecations.nix index a6bd1074f..b8c3e86bc 100644 --- a/modules/lib/deprecations.nix +++ b/modules/lib/deprecations.nix @@ -193,6 +193,7 @@ optionUsesDefaultPriority = canDeferWarning && optionInfo.highestPrio >= warningPriority; usingLegacyBranch = lib.versionOlder stateVersion since; + valuesEqual = legacy.value == current.value; in assert lib.assertMsg (!deferWarningToConfig || canDeferWarning) '' `lib.hm.deprecations.mkStateVersionOptionDefault` requires both `config` and `options` @@ -200,7 +201,10 @@ ''; { default = - if usingLegacyBranch && !deferWarningToConfig then lib.warn warning legacy.value else current.value; + if usingLegacyBranch && !deferWarningToConfig && !valuesEqual then + lib.warn warning legacy.value + else + current.value; defaultText = lib.literalExpression '' if lib.versionAtLeast config.home.stateVersion "${since}" then ${currentText} else ${legacyText} ''; @@ -209,6 +213,7 @@ shouldWarn = deferWarningToConfig && usingLegacyBranch + && !valuesEqual && ( if lib.isFunction shouldWarn then shouldWarn { inherit optionInfo optionUsesDefaultPriority; } diff --git a/tests/lib/types/state-version-option-default-deferred.nix b/tests/lib/types/state-version-option-default-deferred.nix index 3bf8de51f..f82d3575e 100644 --- a/tests/lib/types/state-version-option-default-deferred.nix +++ b/tests/lib/types/state-version-option-default-deferred.nix @@ -63,6 +63,18 @@ let expectedWarn = true; expectedPriority = false; }; + equalValues = { + default = mkDeferredDefault "equalValues" { + legacy.value = { + FOO = "same"; + }; + current.value = { + FOO = "same"; + }; + }; + expectedWarn = false; + expectedPriority = false; + }; }; in { @@ -111,6 +123,7 @@ in }; priorityOnlyExplicit.BAR = "explicit"; partial.BAR = "partial"; + equalValues = { }; }; asserts.warnings.expected = lib.flatten ( @@ -140,6 +153,9 @@ in } partialFoo=${(effectiveValue cases.partial.default config.test.values.partial).FOO or ""} partialBar=${(effectiveValue cases.partial.default config.test.values.partial).BAR or ""} + equalValuesFoo=${ + (effectiveValue cases.equalValues.default config.test.values.equalValues).FOO or "" + } ''; nmt.script = '' @@ -151,6 +167,7 @@ in priorityOnlyExplicitBar=explicit partialFoo=legacy partialBar=partial + equalValuesFoo= ''} ''; }; diff --git a/tests/lib/types/state-version-option-default.nix b/tests/lib/types/state-version-option-default.nix index bd1727a45..359d1555f 100644 --- a/tests/lib/types/state-version-option-default.nix +++ b/tests/lib/types/state-version-option-default.nix @@ -28,6 +28,18 @@ let legacy.value = "legacy"; current.value = "new"; }; + + equalDefault = lib.hm.deprecations.mkStateVersionOptionDefault { + stateVersion = "25.11"; + since = "26.05"; + optionPath = [ + "test" + "values" + "equal" + ]; + legacy.value = null; + current.value = null; + }; in { options.test.values = { @@ -54,6 +66,14 @@ in defaultText ; }; + + equal = lib.mkOption { + type = lib.types.nullOr lib.types.str; + inherit (equalDefault) + default + defaultText + ; + }; }; config = { @@ -77,6 +97,7 @@ in legacy=${config.test.values.legacy} new=${config.test.values.new} pinnedLegacy=${config.test.values.pinnedLegacy} + equal=${if config.test.values.equal == null then "null" else config.test.values.equal} ''; test.asserts.evalWarnings.expected = [ @@ -95,6 +116,7 @@ in legacy=legacy new=new pinnedLegacy=legacy + equal=null ''} ''; };