From aa1c58f6ee8a3ad6ad569f34477192462533c16b Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Fri, 14 Jun 2024 17:26:58 -0700 Subject: [PATCH] feat: support submodule longhand --- lib/src/modules/default.test.nix | 39 ++++++++++++++++++++++++++++++++ lib/src/types/default.nix | 7 +++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/src/modules/default.test.nix b/lib/src/modules/default.test.nix index 9b0bacc..5b1cea6 100644 --- a/lib/src/modules/default.test.nix +++ b/lib/src/modules/default.test.nix @@ -454,5 +454,44 @@ in { }; in evaluated.config.aux.x.message == expected; + + "submodules without shorthand" = let + expected = "Hello, World!"; + evaluated = lib.modules.run { + modules = [ + { + options = { + aux = lib.options.create { + type = lib.types.submodules.of { + shorthand = false; + modules = [ + { + options.message = lib.options.create { + type = lib.types.string; + }; + } + ]; + }; + }; + }; + config = { + aux = { + options = { + message2 = lib.options.create { + type = lib.types.string; + }; + }; + + config = { + message = expected; + message2 = expected; + }; + }; + }; + } + ]; + }; + in + evaluated.config.aux.message == evaluated.config.aux.message2; }; } diff --git a/lib/src/types/default.nix b/lib/src/types/default.nix index a3bc880..6e6a8ed 100644 --- a/lib/src/types/default.nix +++ b/lib/src/types/default.nix @@ -761,10 +761,11 @@ lib: { modules, args ? {}, description ? null, + shorthand ? true, }: let getModules = builtins.map ( definition: - if builtins.isAttrs definition + if shorthand && builtins.isAttrs definition then { __file__ = definition.__file__; config = definition.value; @@ -816,7 +817,7 @@ lib: { getSubModules = modules; withSubModules = modules: lib.types.submodules.of { - inherit args description modules; + inherit args description modules shorthand; }; children = lib.attrs.when (freeform != null) { inherit freeform; @@ -826,7 +827,7 @@ lib: { // { type = lib.types.submodules.of; payload = { - inherit modules args description; + inherit modules args description shorthand; }; merge = x: y: { modules = x.modules ++ y.modules;