summary refs log tree commit diff
path: root/lib/tests/modules/functionTo
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-05-13 08:59:27 +0200
committerRobert Hensing <robert@roberthensing.nl>2022-05-13 09:01:05 +0200
commit06da97fc3a753e0bbebc03ebd63bb1bde2cdda03 (patch)
tree7983cda12b7a622357d2964d54b7ac37c091bf57 /lib/tests/modules/functionTo
parentf771d397500b5138329bd206af2634086d51d108 (diff)
downloadnixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar.gz
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar.bz2
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar.lz
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar.xz
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.tar.zst
nixpkgs-06da97fc3a753e0bbebc03ebd63bb1bde2cdda03.zip
lib.types.functionTo: Support type merging
Diffstat (limited to 'lib/tests/modules/functionTo')
-rw-r--r--lib/tests/modules/functionTo/submodule-options.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/tests/modules/functionTo/submodule-options.nix b/lib/tests/modules/functionTo/submodule-options.nix
new file mode 100644
index 00000000000..7bf70823150
--- /dev/null
+++ b/lib/tests/modules/functionTo/submodule-options.nix
@@ -0,0 +1,59 @@
+{ 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 { };
+          });
+        };
+      };
+    })
+
+    # fun.<function-body>.b
+    ({ ... }: {
+      options = {
+        fun = lib.mkOption {
+          type = types.functionTo (types.submodule {
+            options.b = lib.mkOption { };
+          });
+        };
+      };
+    })
+  ];
+
+  options = {
+    result = 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: { inherit (input) a; })
+      (input: { inherit (input) b; })
+      (input: {
+        b = lib.mkForce input.c;
+      })
+    ];
+}