From 05958f27e2b9a99a058ef5db5f2be1d73c4afd96 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 19 Jan 2025 16:07:39 +0100 Subject: [PATCH] lib/types: types.{unique,uniq} deprecate functor.wrapped in favor of functor.payload.elemType --- doc/release-notes/rl-2505.section.md | 1 + lib/tests/modules.sh | 10 ++++++++-- lib/tests/modules/deprecated-wrapped.nix | 11 +++++++++++ lib/types.nix | 4 +++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index 58bb1371f1bc..2a44045fecb3 100644 --- a/doc/release-notes/rl-2505.section.md +++ b/doc/release-notes/rl-2505.section.md @@ -75,6 +75,7 @@ - `functor.wrapped` is now deprecated for some types and using it will give a warning with migration instructions. It is deprecated for these types: - `lib.types.attrsWith` - `lib.types.listOf` + - `lib.types.unique` and `lib.types.uniq` - 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 1505782547f5..dbbb92d4400d 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -413,8 +413,14 @@ 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.listOf.type.functor.wrapped ./deprecated-wrapped.nix NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedListOf.type.functor.wrapped ./deprecated-wrapped.nix -NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.listOf.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.mergedListOf.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.unique.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.mergedUnique.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix +# unique / uniq +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.unique.type.functor.wrapped ./deprecated-wrapped.nix +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedUnique.type.functor.wrapped ./deprecated-wrapped.nix + +NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.unique.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.mergedUnique.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 8d363a2ad344..dc9771ec38c1 100644 --- a/lib/tests/modules/deprecated-wrapped.nix +++ b/lib/tests/modules/deprecated-wrapped.nix @@ -6,6 +6,7 @@ let # attrsOf uses attrsWith internally attrsOf listOf + unique ; in { @@ -26,6 +27,13 @@ in options.mergedListOf = mkOption { type = listOf (listOf types.str); }; + # unique + options.unique = mkOption { + type = unique { message = ""; } (listOf types.str); + }; + options.mergedUnique = mkOption { + type = unique { message = ""; } (listOf types.str); + }; } ) # Module B @@ -38,6 +46,9 @@ in options.mergedListOf = mkOption { type = listOf (listOf types.str); }; + options.mergedUnique = mkOption { + type = unique { message = ""; } (listOf types.str); + }; } ) ]; diff --git a/lib/types.nix b/lib/types.nix index cdba500ae07f..62aa337c167a 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -844,7 +844,9 @@ rec { getSubOptions = type.getSubOptions; getSubModules = type.getSubModules; substSubModules = m: uniq (type.substSubModules m); - functor = (defaultFunctor name) // { wrapped = type; }; + functor = elemTypeFunctor name { elemType = type; } // { + type = payload: types.unique { inherit message; } payload.elemType; + }; nestedTypes.elemType = type; };