mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
@@ -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; }
|
||||
|
||||
@@ -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=
|
||||
''}
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -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
|
||||
''}
|
||||
'';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user