From 53e5fd67f87348cb1381b79a50137013c77ca702 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Thu, 27 Aug 2026 11:15:47 +0200 Subject: [PATCH 1/2] test: add test for use of in types.submodule --- tests.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests.nix b/tests.nix index 5149660..7360243 100644 --- a/tests.nix +++ b/tests.nix @@ -255,6 +255,22 @@ in ]; }; + import-tree."test can be used in submodule" = { + expr = + (lib.evalModules { + modules = [ + { + options.subModule = lib.mkOption { + type = lib.types.submodule (lit ./tree/modules/hello-option); + }; + config.subModule = lit ./tree/modules/hello-world; + } + ]; + }).config.subModule.hello; + + expected = "world"; + }; + leaves."test loads from hidden directory but excludes sub-hidden" = { expr = lit.leaves ./tree/a/b/_c; expected = [ ./tree/a/b/_c/d/e.nix ]; From 0b1a8933a6fb5f9c8b60bd9beaddacc663e966bc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Thu, 27 Aug 2026 12:02:01 +0200 Subject: [PATCH 2/2] feat: make result return lambda to allow use in type.submodule ie. implement workaround in https://github.com/NixOS/nixpkgs/issues/377575#issuecomment-4936090004 this also remove one level of module nesting, so could be seen as a simplification too. Fix failing test introduced in previous commit. --- default.nix | 7 +++++-- tests.nix | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/default.nix b/default.nix index 0526e7d..813019f 100644 --- a/default.nix +++ b/default.nix @@ -11,7 +11,7 @@ let }: path: let - result = if pipef == null then { imports = [ module ]; } else pipef (leaves path); + result = if pipef == null then module else pipef (leaves path); # module stays a function: callers may apply it as a module function, and # keeping it a lambda defers the tree read (`leaves path`) until module-eval @@ -195,10 +195,13 @@ let functor = self: arg: + if builtins.isFunction arg && builtins.functionArgs arg == { } then arg self # arg is a combinator pass the self import-tree obj + else if inModuleEval arg then + perform self.__config [ ] arg else - perform self.__config (if inModuleEval arg then [ ] else arg); + perform self.__config arg; callable = let diff --git a/tests.nix b/tests.nix index 7360243..ac5eeee 100644 --- a/tests.nix +++ b/tests.nix @@ -189,14 +189,13 @@ in expected = [ ./tree/x/y.nix ]; }; - import-tree."test returns a module with a single imported nested module having leaves" = { + import-tree."test returns a lambda-module with nested module having leaves" = { expr = let oneElement = arr: if lib.length arr == 1 then lib.elemAt arr 0 else throw "Expected one element"; - module = it ./tree/x; - inner = (oneElement module.imports) { inherit lib; }; + module = it ./tree/x { inherit lib; }; in - oneElement inner.imports; + oneElement module.imports; expected = ./tree/x/y.nix; };