From ad853c13680ac6c28ebe9a13a5b2973eb7573221 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Mon, 29 Jan 2024 22:29:44 +0300 Subject: [PATCH 1/2] types.nix: fix nonEmptyListOf --- lib/types.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/types.nix b/lib/types.nix index cea63c598321..7b2062f13059 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -557,6 +557,7 @@ rec { in list // { description = "non-empty ${optionDescriptionPhrase (class: class == "noun") list}"; emptyValue = { }; # no .value attr, meaning unset + substSubModules = m: nonEmptyListOf (elemType.substSubModules m); }; attrsOf = elemType: mkOptionType rec { From 7dea495d34f6ae7a82d676bfbb4ec8d90587784c Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Tue, 30 Jan 2024 21:32:34 +0300 Subject: [PATCH 2/2] feat: add test for nonEmptyListOf submodule --- lib/tests/modules.sh | 1 + lib/tests/modules/error-nonEmptyListOf-submodule.nix | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 lib/tests/modules/error-nonEmptyListOf-submodule.nix diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index a90ff4ad9a2f..0755670c5987 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -101,6 +101,7 @@ checkConfigError 'It seems as if you.re trying to declare an option by placing i checkConfigError 'It seems as if you.re trying to declare an option by placing it into .config. rather than .options.' config.nest.wrong2 ./error-mkOption-in-config.nix checkConfigError 'The option .sub.wrong2. does not exist. Definition values:' config.sub ./error-mkOption-in-submodule-config.nix checkConfigError '.*This can happen if you e.g. declared your options in .types.submodule.' config.sub ./error-mkOption-in-submodule-config.nix +checkConfigError '.*A definition for option .bad. is not of type .non-empty .list of .submodule...\.' config.bad ./error-nonEmptyListOf-submodule.nix # types.pathInStore checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix diff --git a/lib/tests/modules/error-nonEmptyListOf-submodule.nix b/lib/tests/modules/error-nonEmptyListOf-submodule.nix new file mode 100644 index 000000000000..1189e8891560 --- /dev/null +++ b/lib/tests/modules/error-nonEmptyListOf-submodule.nix @@ -0,0 +1,7 @@ +{ lib, ... }: +{ + options.bad = lib.mkOption { + type = lib.types.nonEmptyListOf (lib.types.submodule { }); + default = [ ]; + }; +}