From b2ca8a612aaf9dfb6a87b50097e30aadc25f3443 Mon Sep 17 00:00:00 2001 From: Victor Hugo Borja Date: Thu, 14 May 2026 10:58:26 -0600 Subject: [PATCH] feat: Compose import-tree by juxtaposition (inspired by denful/ned) --- Justfile | 4 ++-- checkmate/modules/tests.nix | 5 +++++ default.nix | 29 ++++++++++++++++++----------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Justfile b/Justfile index 2e3573c..7598c53 100644 --- a/Justfile +++ b/Justfile @@ -8,8 +8,8 @@ ci: just test fmt *args: - nix run github:denful/checkmate#fmt --override-input target path:. {{args}} + nix run github:denful/checkmate#fmt --override-input target path:. -L {{args}} test *args: - nix flake check github:denful/checkmate --override-input target . {{args}} + nix flake check github:denful/checkmate --override-input target . -L {{args}} diff --git a/checkmate/modules/tests.nix b/checkmate/modules/tests.nix index c8db2a4..a9738b2 100644 --- a/checkmate/modules/tests.nix +++ b/checkmate/modules/tests.nix @@ -270,6 +270,11 @@ in }).config.foo; expected = 22; }; + + combinator."test combinator syntax to compose import-tree" = { + expr = it (it: it.withLib lib) (it: it.leafs) ../tree/_scoped; + expected = [ ../tree/_scoped/foo.nix ]; + }; }; } diff --git a/default.nix b/default.nix index 05adaf7..b5eab39 100644 --- a/default.nix +++ b/default.nix @@ -23,19 +23,21 @@ let # module exists so we delay access to lib til we are part of the module system. module = { lib, ... }: + let + files = leafs lib path; + imports = if scoped == { } then files else map scoped-import files; + in { - imports = (if scoped == { } then leafs else scoped-leafs) lib path; + inherit imports; }; - scoped-leafs = - lib: root: - map (builtins.scopedImport ( - { - inherit builtins; - __nixPath = [ ]; - } - // scoped - )) (leafs lib root); + scoped-import = builtins.scopedImport ( + { + inherit builtins; + __nixPath = [ ]; + } + // scoped + ); leafs = lib: @@ -145,7 +147,12 @@ let inModuleEval = and (x: x ? options) builtins.isAttrs; - functor = self: arg: perform self.__config (if inModuleEval arg then [ ] else arg); + functor = + self: arg: + if builtins.isFunction arg && builtins.functionArgs arg == { } then + arg self # arg is a combinator pass the self import-tree obj + else + perform self.__config (if inModuleEval arg then [ ] else arg); callable = let