lib/deprecations: suppress no-op state-version warnings

Closes #9045
This commit is contained in:
Austin Horstman
2026-04-19 22:32:25 -05:00
parent 1e9bdc6d35
commit b85e8fff94
3 changed files with 45 additions and 1 deletions

View File

@@ -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; }

View File

@@ -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=
''}
'';
};

View File

@@ -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
''}
'';
};