about summary refs log tree commit diff
path: root/lib/tests
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2022-05-17 22:22:21 +0200
committerGitHub <noreply@github.com>2022-05-17 22:22:21 +0200
commit2d1a34b8cc4a28adcdb97fb2872e303a9b8ded57 (patch)
tree50a07eef12927168c31e66b3cb81553c7fc84d2d /lib/tests
parent2a093dadc1dae7f188b2db7a758fc03690dc0800 (diff)
parent0b02135d3bdf49f9154f60e7a4c9d54d5e0ee70d (diff)
Merge pull request #172813 from hercules-ci/functionTo-properly
`lib.types.functionTo` type merging and docs
Diffstat (limited to 'lib/tests')
-rwxr-xr-xlib/tests/modules.sh2
-rw-r--r--lib/tests/modules/functionTo/submodule-options.nix61
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 82d3dd96e88bb..487fcd93641b8 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -290,6 +290,8 @@ checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix
 checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
 checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix
 checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix
+checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix
+checkConfigOutput '^"fun.\[function body\].a fun.\[function body\].b"$' config.optionsResult ./functionTo/submodule-options.nix
 
 # moduleType
 checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix
diff --git a/lib/tests/modules/functionTo/submodule-options.nix b/lib/tests/modules/functionTo/submodule-options.nix
new file mode 100644
index 0000000000000..b884892efd6aa
--- /dev/null
+++ b/lib/tests/modules/functionTo/submodule-options.nix
@@ -0,0 +1,61 @@
+{ lib, config, options, ... }:
+let
+  inherit (lib) types;
+in
+{
+  imports = [
+
+    # fun.<function-body>.a
+    ({ ... }: {
+      options = {
+        fun = lib.mkOption {
+          type = types.functionTo (types.submodule {
+            options.a = lib.mkOption { default = "a"; };
+          });
+        };
+      };
+    })
+
+    # fun.<function-body>.b
+    ({ ... }: {
+      options = {
+        fun = lib.mkOption {
+          type = types.functionTo (types.submodule {
+            options.b = lib.mkOption { default = "b"; };
+          });
+        };
+      };
+    })
+  ];
+
+  options = {
+    result = lib.mkOption
+      {
+        type = types.str;
+        default = lib.concatStringsSep " " (lib.attrValues (config.fun (throw "shouldn't use input param")));
+      };
+
+    optionsResult = lib.mkOption
+      {
+        type = types.str;
+        default = lib.concatStringsSep " "
+          (lib.concatLists
+            (lib.mapAttrsToList
+              (k: v:
+                if k == "_module"
+                then [ ]
+                else [ (lib.showOption v.loc) ]
+              )
+              (
+                (options.fun.type.getSubOptions [ "fun" ])
+              )
+            )
+          );
+      };
+  };
+
+  config.fun = lib.mkMerge
+    [
+      (input: { b = "bee"; })
+    ];
+}