From f6214eb786bffd05a17941bfe68cdecb0c0438af Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 19 Jan 2025 16:22:24 +0100 Subject: [PATCH] lib/types: types.functionTo deprecate functor.wrapped in favor of functor.payload.elemType --- doc/release-notes/rl-2505.section.md | 1 + lib/tests/modules.sh | 6 ++++++ lib/tests/modules/deprecated-wrapped.nix | 11 +++++++++++ lib/types.nix | 4 +++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index c71ac169d78b..240cda17b1eb 100644 --- a/doc/release-notes/rl-2505.section.md +++ b/doc/release-notes/rl-2505.section.md @@ -77,6 +77,7 @@ - `lib.types.listOf` - `lib.types.unique` and `lib.types.uniq` - `lib.types.nullOr` + - `lib.types.functionTo` - 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 5bdc6e983501..ffdc1505f06d 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -427,6 +427,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.nullOr.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.mergedNullOr.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix +# functionTo +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.functionTo.type.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.functor.wrapped ./deprecated-wrapped.nix + +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 # 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 .*' \ diff --git a/lib/tests/modules/deprecated-wrapped.nix b/lib/tests/modules/deprecated-wrapped.nix index fcdfef7dea71..7db64edfcce3 100644 --- a/lib/tests/modules/deprecated-wrapped.nix +++ b/lib/tests/modules/deprecated-wrapped.nix @@ -8,6 +8,7 @@ let listOf unique nullOr + functionTo ; in { @@ -42,6 +43,13 @@ in options.mergedNullOr = mkOption { type = nullOr (listOf types.str); }; + # nullOr + options.functionTo = mkOption { + type = functionTo (listOf types.str); + }; + options.mergedFunctionTo = mkOption { + type = functionTo (listOf types.str); + }; } ) # Module B @@ -60,6 +68,9 @@ in options.mergedNullOr = mkOption { type = nullOr (listOf types.str); }; + options.mergedFunctionTo = mkOption { + type = functionTo (listOf types.str); + }; } ) ]; diff --git a/lib/types.nix b/lib/types.nix index f38f96c33786..24d5192225a3 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -887,7 +887,9 @@ rec { getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "" ]); getSubModules = elemType.getSubModules; substSubModules = m: functionTo (elemType.substSubModules m); - functor = (defaultFunctor "functionTo") // { wrapped = elemType; }; + functor = (elemTypeFunctor "functionTo" { inherit elemType; }) // { + type = payload: types.functionTo payload.elemType; + }; nestedTypes.elemType = elemType; };