mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
Merge pull request #160487 from Infinisil/emptyValueFixes
Minor fixes for `emptyValue`s
This commit is contained in:
commit
67596d3fcf
|
@ -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 <<EOF
|
||||
====== module tests ======
|
||||
$pass Pass
|
||||
|
|
36
lib/tests/modules/emptyValues.nix
Normal file
36
lib/tests/modules/emptyValues.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
|
||||
options = {
|
||||
int = lib.mkOption {
|
||||
type = types.lazyAttrsOf types.int;
|
||||
};
|
||||
list = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.listOf types.int);
|
||||
};
|
||||
nonEmptyList = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.nonEmptyListOf types.int);
|
||||
};
|
||||
attrs = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.attrsOf types.int);
|
||||
};
|
||||
null = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.nullOr types.int);
|
||||
};
|
||||
submodule = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.submodule {});
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
int.a = lib.mkIf false null;
|
||||
list.a = lib.mkIf false null;
|
||||
nonEmptyList.a = lib.mkIf false null;
|
||||
attrs.a = lib.mkIf false null;
|
||||
null.a = lib.mkIf false null;
|
||||
submodule.a = lib.mkIf false null;
|
||||
};
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue