From 382289027f92ff3973f14d983a55b183c9b1c0bd Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 2 Aug 2021 21:18:40 +0200 Subject: [PATCH 1/2] lib/types: Fix emptyValue of listOf and nonEmptyListOf An empty list is [], not {}! Also, non-empty lists shouldn't have a default of an empty list! --- lib/types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index f2f9b2bca985..3fa9d881a650 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -390,7 +390,7 @@ rec { ).optionalValue ) def.value ) defs))); - emptyValue = { value = {}; }; + emptyValue = { value = []; }; getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]); getSubModules = elemType.getSubModules; substSubModules = m: listOf (elemType.substSubModules m); @@ -402,7 +402,7 @@ rec { let list = addCheck (types.listOf elemType) (l: l != []); in list // { description = "non-empty " + list.description; - # Note: emptyValue is left as is, because another module may define an element. + emptyValue = { }; # no .value attr, meaning unset }; attrsOf = elemType: mkOptionType rec { From b333395be54397a62e6befe2bc91664f53306b41 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 15 Oct 2021 16:48:38 +0200 Subject: [PATCH 2/2] lib/tests: Add tests for emptyValue --- lib/tests/modules.sh | 9 ++++++++ lib/tests/modules/emptyValues.nix | 36 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 lib/tests/modules/emptyValues.nix diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 590937da5b8f..88d152d39352 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -284,6 +284,15 @@ checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-var checkConfigOutput '^"a y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix +## emptyValue's +checkConfigOutput "[ ]" config.list.a ./emptyValues.nix +checkConfigOutput "{ }" config.attrs.a ./emptyValues.nix +checkConfigOutput "null" config.null.a ./emptyValues.nix +checkConfigOutput "{ }" config.submodule.a ./emptyValues.nix +# These types don't have empty values +checkConfigError 'The option .int.a. is used but not defined' config.int.a ./emptyValues.nix +checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a ./emptyValues.nix + cat <