From b333395be54397a62e6befe2bc91664f53306b41 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 15 Oct 2021 16:48:38 +0200 Subject: lib/tests: Add tests for emptyValue --- lib/tests/modules.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/tests/modules.sh') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 590937da5b8..88d152d3935 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 < Date: Mon, 2 Aug 2021 21:42:45 +0200 Subject: lib/types: Introduce types.raw for unprocessed values --- lib/tests/modules.sh | 6 +++++ lib/tests/modules/raw.nix | 30 ++++++++++++++++++++++ lib/types.nix | 7 +++++ .../doc/manual/development/option-types.section.md | 11 ++++++++ .../from_md/development/option-types.section.xml | 19 ++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 lib/tests/modules/raw.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 88d152d3935..a1c592cf4ef 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -293,6 +293,12 @@ checkConfigOutput "{ }" config.submodule.a ./emptyValues.nix 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 +## types.raw +checkConfigOutput "{ foo = ; }" config.unprocessedNesting ./raw.nix +checkConfigOutput "10" config.processedToplevel ./raw.nix +checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix +checkConfigOutput "bar" config.priorities ./raw.nix + cat < + + + types.raw + + + + A type which doesn’t do any checking, merging or nested + evaluation. It accepts a single arbitrary value that is not + recursed into, making it useful for values coming from + outside the module system, such as package sets or arbitrary + data. Options of this type are still evaluated according to + priorities and conditionals, so mkForce, + mkIf and co. still work on the option + value itself, but not for any value nested within it. This + type should only be used when checking, merging and nested + evaluation are not desirable. + + + types.attrs -- cgit 1.4.1 From 5cbeddfde486ca5524baeaf3da6e8944075cf463 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 8 Dec 2021 19:02:29 +0100 Subject: lib.types: Introduce `types.optionType` This type correctly merges multiple option types together while also annotating them with file information. In a future commit this will be used for `_module.freeformType` --- lib/tests/modules.sh | 7 +++++ lib/tests/modules/optionTypeFile.nix | 28 +++++++++++++++++++ lib/tests/modules/optionTypeMerging.nix | 27 +++++++++++++++++++ lib/types.nix | 31 +++++++++++++++++++++- .../doc/manual/development/option-types.section.md | 7 +++++ .../from_md/development/option-types.section.xml | 14 ++++++++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 lib/tests/modules/optionTypeFile.nix create mode 100644 lib/tests/modules/optionTypeMerging.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index a1c592cf4ef..d11f32e5996 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -299,6 +299,13 @@ checkConfigOutput "10" config.processedToplevel ./raw.nix checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix checkConfigOutput "bar" config.priorities ./raw.nix +# Test that types.optionType merges types correctly +checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix +checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix + +# Test that types.optionType correctly annotates option locations +checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix + cat < + + + types.optionType + + + + The type of an option’s type. Its merging operation ensures + that nested options have the correct file location + annotated, and that if possible, multiple option definitions + are correctly merged together. The main use case is as the + type of the _module.freeformType option. + + + types.attrs -- cgit 1.4.1 From 023fa7b9239e645f7dfcbbe3ee82ab0093f9978d Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 8 Dec 2021 19:13:14 +0100 Subject: lib.modules: Use types.optionType for _module.freeformType This ensures that the module file locations are propagated to the freeform type, which makes it so that submodules in freeform types now have their declaration location shown in the manual, fixing https://github.com/NixOS/nixpkgs/issues/132085. In addition, this also newly allows freeformTypes to be declared multiple times and all declarations being merged together according to normal option merging. This also removes some awkwardness regarding the type of `freeformType` --- lib/modules.nix | 3 +-- lib/tests/modules.sh | 5 +++++ lib/tests/modules/freeform-submodules.nix | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lib/tests/modules/freeform-submodules.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/modules.nix b/lib/modules.nix index e9fc1007fc2..79d54e4a538 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -151,8 +151,7 @@ rec { }; _module.freeformType = mkOption { - # Disallow merging for now, but could be implemented nicely with a `types.optionType` - type = types.nullOr (types.uniq types.attrs); + type = types.nullOr types.optionType; internal = true; default = null; description = '' diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index d11f32e5996..e4bb7ad2190 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -240,6 +240,11 @@ checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep- checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix +# submodules in freeformTypes should have their locations annotated +checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix +# freeformTypes can get merged using `types.type`, including submodules +checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix +checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix ## types.anything # Check that attribute sets are merged recursively diff --git a/lib/tests/modules/freeform-submodules.nix b/lib/tests/modules/freeform-submodules.nix new file mode 100644 index 00000000000..3910435a7b5 --- /dev/null +++ b/lib/tests/modules/freeform-submodules.nix @@ -0,0 +1,22 @@ +{ lib, options, ... }: with lib.types; { + + options.fooDeclarations = lib.mkOption { + default = (options.free.type.getSubOptions [])._freeformOptions.foo.declarations; + }; + + options.free = lib.mkOption { + type = submodule { + config._module.freeformType = lib.mkMerge [ + (attrsOf (submodule { + options.foo = lib.mkOption {}; + })) + (attrsOf (submodule { + options.bar = lib.mkOption {}; + })) + ]; + }; + }; + + config.free.xxx.foo = 10; + config.free.yyy.bar = 10; +} -- cgit 1.4.1 From d030e2109fd491e32cb48df54d100aa608551298 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 24 Jan 2022 15:58:17 +0100 Subject: lib.modules: Let module declare options directly in bare submodule ... where a bare submodule is an option that has a type like `submoduleWith x`, as opposed to `attrsOf (submoduleWith x)`. This makes migration unnecessary when introducing a freeform type in an existing option tree. Closes #146882 --- lib/modules.nix | 22 +++++++++++++++++++++- lib/tests/modules.sh | 5 +++++ .../modules/declare-bare-submodule-deep-option.nix | 10 ++++++++++ .../declare-bare-submodule-nested-option.nix | 18 ++++++++++++++++++ lib/tests/modules/declare-bare-submodule.nix | 12 ++++++++++++ lib/tests/modules/define-bare-submodule-values.nix | 4 ++++ lib/types.nix | 5 +++++ 7 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 lib/tests/modules/declare-bare-submodule-deep-option.nix create mode 100644 lib/tests/modules/declare-bare-submodule-nested-option.nix create mode 100644 lib/tests/modules/declare-bare-submodule.nix create mode 100644 lib/tests/modules/define-bare-submodule-values.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/modules.nix b/lib/modules.nix index 79d54e4a538..bde89123cd9 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -474,6 +474,18 @@ rec { [{ inherit (module) file; inherit value; }] ) configs; + # Convert an option tree decl to a submodule option decl + optionTreeToOption = decl: + if isOption decl.options + then decl + else decl // { + options = mkOption { + type = types.submoduleWith { + modules = [ { options = decl.options; } ]; + }; + }; + }; + resultsByName = mapAttrs (name: decls: # We're descending into attribute ‘name’. let @@ -493,7 +505,15 @@ rec { firstOption = findFirst (m: isOption m.options) "" decls; firstNonOption = findFirst (m: !isOption m.options) "" decls; in - throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'." + if firstOption.options.type?isSubmodule && firstOption.options.type.isSubmodule + then + let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls)); + in { + matchedOptions = evalOptionValue loc opt defns'; + unmatchedDefns = []; + } + else + throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'." else mergeModules' loc decls defns) declsByName; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index e4bb7ad2190..3591b8f1e6f 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -62,6 +62,11 @@ checkConfigError() { checkConfigOutput '^false$' config.enable ./declare-enable.nix checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix +checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix +checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix +checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix +checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix + # Check integer types. # unsigned checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix diff --git a/lib/tests/modules/declare-bare-submodule-deep-option.nix b/lib/tests/modules/declare-bare-submodule-deep-option.nix new file mode 100644 index 00000000000..06ad1f6e0a5 --- /dev/null +++ b/lib/tests/modules/declare-bare-submodule-deep-option.nix @@ -0,0 +1,10 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; +in +{ + options.bare-submodule.deep = mkOption { + type = types.int; + default = 2; + }; +} diff --git a/lib/tests/modules/declare-bare-submodule-nested-option.nix b/lib/tests/modules/declare-bare-submodule-nested-option.nix new file mode 100644 index 00000000000..009dd4d6cb3 --- /dev/null +++ b/lib/tests/modules/declare-bare-submodule-nested-option.nix @@ -0,0 +1,18 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; +in +{ + options.bare-submodule = mkOption { + type = types.submoduleWith { + modules = [ + { + options.nested = mkOption { + type = types.int; + default = 1; + }; + } + ]; + }; + }; +} diff --git a/lib/tests/modules/declare-bare-submodule.nix b/lib/tests/modules/declare-bare-submodule.nix new file mode 100644 index 00000000000..298c71e3ca0 --- /dev/null +++ b/lib/tests/modules/declare-bare-submodule.nix @@ -0,0 +1,12 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; +in +{ + options.bare-submodule = mkOption { + type = types.submoduleWith { + modules = [ ]; + }; + default = {}; + }; +} diff --git a/lib/tests/modules/define-bare-submodule-values.nix b/lib/tests/modules/define-bare-submodule-values.nix new file mode 100644 index 00000000000..00ede929ee6 --- /dev/null +++ b/lib/tests/modules/define-bare-submodule-values.nix @@ -0,0 +1,4 @@ +{ + bare-submodule.nested = 42; + bare-submodule.deep = 420; +} diff --git a/lib/types.nix b/lib/types.nix index 3fcac9c31b3..51046c2c31b 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -642,6 +642,11 @@ rec { else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values"; }; }; + } // { + # Submodule-typed options get special treatment in order to facilitate + # certain migrations, such as the addition of freeformTypes onto + # existing option trees. + isSubmodule = true; }; # A value from a set of allowed ones. -- cgit 1.4.1 From 11537c9c0239dc4ae52477faa78a4a0a7bdf206c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 28 Feb 2022 22:39:56 +0100 Subject: lib.modules: Improve option-is-prefix error message --- lib/modules.nix | 24 +++++++++++++++++++++--- lib/tests/modules.sh | 6 ++++++ lib/tests/modules/declare-set.nix | 12 ++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 lib/tests/modules/declare-set.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/modules.nix b/lib/modules.nix index 62e9615d25b..7d9c55f9a15 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -9,6 +9,7 @@ let catAttrs concatLists concatMap + concatStringsSep elem filter findFirst @@ -46,6 +47,20 @@ let showOption unknownModule ; + + showDeclPrefix = loc: decl: prefix: + " - option(s) with prefix `${showOption (loc ++ [prefix])}' in module `${decl._file}'"; + showRawDecls = loc: decls: + concatStringsSep "\n" + (sort (a: b: a < b) + (concatMap + (decl: map + (showDeclPrefix loc decl) + (attrNames decl.options) + ) + decls + )); + in rec { @@ -500,7 +515,7 @@ rec { unmatchedDefns = []; } else if optionDecls != [] then - if (lib.head optionDecls).options.type.name == "submodule" + if all (x: x.options.type.name == "submodule") optionDecls # Raw options can only be merged into submodules. Merging into # attrsets might be nice, but ambiguous. Suppose we have # attrset as a `attrsOf submodule`. User declares option @@ -509,7 +524,7 @@ rec { # b. option `foo.bar` is available in all `attrset.*` # c. reject and require "" as a reminder that it behaves like (b). # d. magically combine (a) and (c). - # All options are merely syntax sugar though. + # All of the above are merely syntax sugar though. then let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls)); in { @@ -519,8 +534,11 @@ rec { else let firstNonOption = findFirst (m: !isOption m.options) "" decls; + nonOptions = filter (m: !isOption m.options) decls; in - throw "The option `${showOption loc}' in `${(lib.head optionDecls)._file}' is a prefix of options in `${firstNonOption._file}'." + throw "The option `${showOption loc}' in module `${(lib.head optionDecls)._file}' would be a parent of the following options, but its type `${(lib.head optionDecls).options.type.description or ""}' does not support nested options.\n${ + showRawDecls loc nonOptions + }" else mergeModules' loc decls defns) declsByName; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 3591b8f1e6f..e903714a720 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -309,6 +309,12 @@ checkConfigOutput "10" config.processedToplevel ./raw.nix checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix checkConfigOutput "bar" config.priorities ./raw.nix +## Option collision +checkConfigError \ + 'The option .set. in module .*/declare-set.nix. would be a parent of the following options, but its type .attribute set of signed integers. does not support nested options.\n\s*- option[(]s[)] with prefix .set.enable. in module .*/declare-enable-nested.nix.' \ + config.set \ + ./declare-set.nix ./declare-enable-nested.nix + # Test that types.optionType merges types correctly checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix diff --git a/lib/tests/modules/declare-set.nix b/lib/tests/modules/declare-set.nix new file mode 100644 index 00000000000..853418531a8 --- /dev/null +++ b/lib/tests/modules/declare-set.nix @@ -0,0 +1,12 @@ +{ lib, ... }: + +{ + options.set = lib.mkOption { + default = { }; + example = { a = 1; }; + type = lib.types.attrsOf lib.types.int; + description = '' + Some descriptive text + ''; + }; +} -- cgit 1.4.1 From 8baea8b82cc80c6a2843045d5b554f7f65acbc4f Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 28 Feb 2022 22:57:03 +0100 Subject: lib.modules: Make option injection work when shorthandOnlyDefinesConfig --- lib/modules.nix | 1 + lib/tests/modules.sh | 1 + lib/tests/modules/declare-bare-submodule-nested-option.nix | 3 ++- lib/tests/modules/declare-bare-submodule.nix | 8 +++++++- lib/tests/modules/define-shorthandOnlyDefinesConfig-true.nix | 1 + lib/types.nix | 6 +++++- 6 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 lib/tests/modules/define-shorthandOnlyDefinesConfig-true.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/modules.nix b/lib/modules.nix index 7d9c55f9a15..cc045391fcb 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -496,6 +496,7 @@ rec { options = mkOption { type = types.submoduleWith { modules = [ { options = decl.options; } ]; + shorthandOnlyDefinesConfig = null; }; }; }; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index e903714a720..3950d83f584 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -66,6 +66,7 @@ checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.ni checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix +checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix # Check integer types. # unsigned diff --git a/lib/tests/modules/declare-bare-submodule-nested-option.nix b/lib/tests/modules/declare-bare-submodule-nested-option.nix index 009dd4d6cb3..da125c84b25 100644 --- a/lib/tests/modules/declare-bare-submodule-nested-option.nix +++ b/lib/tests/modules/declare-bare-submodule-nested-option.nix @@ -1,10 +1,11 @@ -{ lib, ... }: +{ config, lib, ... }: let inherit (lib) mkOption types; in { options.bare-submodule = mkOption { type = types.submoduleWith { + shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig; modules = [ { options.nested = mkOption { diff --git a/lib/tests/modules/declare-bare-submodule.nix b/lib/tests/modules/declare-bare-submodule.nix index 298c71e3ca0..5402f4ff5a5 100644 --- a/lib/tests/modules/declare-bare-submodule.nix +++ b/lib/tests/modules/declare-bare-submodule.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ config, lib, ... }: let inherit (lib) mkOption types; in @@ -6,7 +6,13 @@ in options.bare-submodule = mkOption { type = types.submoduleWith { modules = [ ]; + shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig; }; default = {}; }; + + # config-dependent options: won't recommend, but useful for making this test parameterized + options.shorthandOnlyDefinesConfig = mkOption { + default = false; + }; } diff --git a/lib/tests/modules/define-shorthandOnlyDefinesConfig-true.nix b/lib/tests/modules/define-shorthandOnlyDefinesConfig-true.nix new file mode 100644 index 00000000000..bd3a73dce34 --- /dev/null +++ b/lib/tests/modules/define-shorthandOnlyDefinesConfig-true.nix @@ -0,0 +1 @@ +{ shorthandOnlyDefinesConfig = true; } diff --git a/lib/types.nix b/lib/types.nix index 3fcac9c31b3..bd4062d555a 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -637,7 +637,11 @@ rec { then lhs.specialArgs // rhs.specialArgs else throw "A submoduleWith option is declared multiple times with the same specialArgs \"${toString (attrNames intersecting)}\""; shorthandOnlyDefinesConfig = - if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig + if lhs.shorthandOnlyDefinesConfig == null + then rhs.shorthandOnlyDefinesConfig + else if rhs.shorthandOnlyDefinesConfig == null + then lhs.shorthandOnlyDefinesConfig + else if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig then lhs.shorthandOnlyDefinesConfig else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values"; }; -- cgit 1.4.1 From c90844aeb97c0d57f3dbb5774f56cddbf5b2a16d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 7 Mar 2022 11:20:30 +0100 Subject: lib/tests/modules: Add test case for duplicate option error file location --- lib/tests/modules.sh | 1 + .../modules/declare-bare-submodule-deep-option-duplicate.nix | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 lib/tests/modules/declare-bare-submodule-deep-option-duplicate.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 3950d83f584..e86b545c466 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -67,6 +67,7 @@ checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix +checkConfigError 'The option .bare-submodule.deep. in .*/declare-bare-submodule-deep-option.nix. is already declared in .*/declare-bare-submodule-deep-option-duplicate.nix' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./declare-bare-submodule-deep-option-duplicate.nix # Check integer types. # unsigned diff --git a/lib/tests/modules/declare-bare-submodule-deep-option-duplicate.nix b/lib/tests/modules/declare-bare-submodule-deep-option-duplicate.nix new file mode 100644 index 00000000000..06ad1f6e0a5 --- /dev/null +++ b/lib/tests/modules/declare-bare-submodule-deep-option-duplicate.nix @@ -0,0 +1,10 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; +in +{ + options.bare-submodule.deep = mkOption { + type = types.int; + default = 2; + }; +} -- cgit 1.4.1 From 55ee7ab4a6b5281cf1c352bc714b07c59c4546ee Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 10 Mar 2022 20:25:49 +0100 Subject: lib.types.optionType: Only merge when necessary --- lib/tests/modules.sh | 3 +++ .../modules/adhoc-freeformType-survives-type-merge.nix | 14 ++++++++++++++ lib/types.nix | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/tests/modules/adhoc-freeformType-survives-type-merge.nix (limited to 'lib/tests/modules.sh') diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index e4bb7ad2190..350fe85e748 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -311,6 +311,9 @@ checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix # Test that types.optionType correctly annotates option locations checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix +# Test that types.optionType leaves types untouched as long as they don't need to be merged +checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix + cat <