diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index 240cda17b1eb..2f9c4a00d6f4 100644 --- a/doc/release-notes/rl-2505.section.md +++ b/doc/release-notes/rl-2505.section.md @@ -78,6 +78,7 @@ - `lib.types.unique` and `lib.types.uniq` - `lib.types.nullOr` - `lib.types.functionTo` + - `lib.types.coercedTo` - Plasma 5 and Qt 5 based versions of associated software are deprecated in NixOS 25.05, and will be removed in NixOS 25.11. Users are encouraged to upgrade to Plasma 6. diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index ffdc1505f06d..2f21e466450d 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -434,6 +434,12 @@ NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribu NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.functionTo.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedFunctionTo.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix +# coercedTo +# Note: test 'nestedTypes.finalType' and 'nestedTypes.coercedType' +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.functor.wrapped ./deprecated-wrapped.nix +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.nestedTypes.finalType.functor.wrapped ./deprecated-wrapped.nix +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.nestedTypes.coercedType.functor.wrapped ./deprecated-wrapped.nix + # Even with multiple assignments, a type error should be thrown if any of them aren't valid checkConfigError 'A definition for option .* is not of type .*' \ config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix diff --git a/lib/tests/modules/deprecated-wrapped.nix b/lib/tests/modules/deprecated-wrapped.nix index 7db64edfcce3..5559cd3e9332 100644 --- a/lib/tests/modules/deprecated-wrapped.nix +++ b/lib/tests/modules/deprecated-wrapped.nix @@ -9,6 +9,7 @@ let unique nullOr functionTo + coercedTo ; in { @@ -43,13 +44,18 @@ in options.mergedNullOr = mkOption { type = nullOr (listOf types.str); }; - # nullOr + # functionTo options.functionTo = mkOption { type = functionTo (listOf types.str); }; options.mergedFunctionTo = mkOption { type = functionTo (listOf types.str); }; + # coercedTo + # Note: coercedTo is a non-mergeable option-type + options.coercedTo = mkOption { + type = coercedTo (listOf types.str) lib.id (listOf types.str); + }; } ) # Module B diff --git a/lib/types.nix b/lib/types.nix index 24d5192225a3..dee93a62e398 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -75,6 +75,7 @@ let # Note that individual attributes can be overriden if needed. elemTypeFunctor = name: { elemType, ... }@payload: { inherit name payload; + wrappedDeprecationMessage = makeWrappedDeprecationMessage payload; type = outer_types.types.${name}; binOp = a: b: let @@ -85,10 +86,10 @@ let null else { elemType = merged; }; - wrappedDeprecationMessage = { loc }: lib.warn '' - The deprecated `${lib.optionalString (loc != null) "type."}functor.wrapped` attribute ${lib.optionalString (loc != null) "of the option `${showOption loc}` "}is accessed, use `${lib.optionalString (loc != null) "type."}nestedTypes.elemType` instead. - '' payload.elemType; }; + makeWrappedDeprecationMessage = payload: { loc }: lib.warn '' + The deprecated `${lib.optionalString (loc != null) "type."}functor.wrapped` attribute ${lib.optionalString (loc != null) "of the option `${showOption loc}` "}is accessed, use `${lib.optionalString (loc != null) "type."}nestedTypes.elemType` instead. + '' payload.elemType; outer_types = @@ -1163,7 +1164,9 @@ rec { getSubModules = finalType.getSubModules; substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m); typeMerge = t: null; - functor = (defaultFunctor name) // { wrapped = finalType; }; + functor = (defaultFunctor name) // { + wrappedDeprecationMessage = makeWrappedDeprecationMessage { elemType = finalType; }; + }; nestedTypes.coercedType = coercedType; nestedTypes.finalType = finalType; };