Outside Module Evaluation
Using import-tree as a File Lister
Section titled “Using import-tree as a File Lister”import-tree doesn’t have to produce module imports. You can use it to get a plain list of files:
import-tree.leafs ./modules# => [ /path/to/modules/a.nix /path/to/modules/b.nix ]The tree reader is implemented with pure builtins, so .leafs, .files and .pipeTo work everywhere — including outside module evaluation — with no setup.
.leafs returns a configured import-tree that, when given a path, produces a flat list of discovered files:
import-tree.leafs ./src# => [ ./src/main.nix ./src/utils.nix ].files is a shortcut for .leafs.result: returns the list directly when paths have already been added via .addPath:
import-tree (i: i.addPath ./modules) (i: i.files)pipeTo
Section titled “pipeTo”.pipeTo takes a function that receives the list of discovered paths, letting you process the results:
import-tree.pipeTo builtins.length ./modules# => 5 (number of .nix files)Combine with .map for powerful pipelines:
import-tree (i: i.map import) (i: i.pipeTo builtins.length) (i: i ./modules)result
Section titled “result”.result evaluates the import-tree with an empty path list, useful when paths are already configured via .addPath:
(import-tree.addPath ./modules).result# equivalent to:(import-tree.addPath ./modules) []