diff --git a/checkmate.nix b/checkmate.nix index a0bff8d..f22d5d9 100644 --- a/checkmate.nix +++ b/checkmate.nix @@ -203,6 +203,23 @@ in expected = [ ./tree/modules/hello-world/mod.nix ]; }; + import-tree."test passes non-paths without string conversion" = { + expr = + let + mod = it [ + { + options.hello = lib.mkOption { + default = "world"; + type = lib.types.str; + }; + } + ]; + res = lib.modules.evalModules { modules = [ mod ]; }; + in + res.config.hello; + expected = "world"; + }; + import-tree."test can take other import-trees as if they were paths" = { expr = (lit.filter (lib.hasInfix "mod")).leafs [ (it.addPath ./tree/modules/hello-option) diff --git a/default.nix b/default.nix index 9ee0c97..b8ae573 100644 --- a/default.nix +++ b/default.nix @@ -35,11 +35,13 @@ let treeFiles x else if hasOutPath x then listFilesRecursive x.outPath - else if lib.pathIsDirectory x then + else if isDirectory x then lib.filesystem.listFilesRecursive x else [ x ]; treeFiles = t: (t.withLib lib).leafs.result; + pathFilter = compose (and filterf initialFilter) toString; + filter = x: if isPathLike x then pathFilter x else filterf x; in lib.pipe [ paths root ] @@ -47,7 +49,7 @@ let (lib.lists.flatten) (map listFilesRecursive) (lib.lists.flatten) - (builtins.filter (compose (and filterf initialFilter) toString)) + (builtins.filter filter) (map mapf) ]; @@ -71,6 +73,10 @@ let attrs: k: f: attrs // { ${k} = f attrs.${k}; }; + isDirectory = and (x: builtins.readFileType x == "directory") isPathLike; + + isPathLike = x: builtins.isPath x || builtins.isString x || hasOutPath x; + hasOutPath = and (x: x ? outPath) builtins.isAttrs; isImportTree = and (x: x ? __config.__functor) builtins.isAttrs;