Transforming Paths
.map takes a function that transforms each discovered path. Transformations are applied after filtering.
Wrapping in Custom Modules
Section titled “Wrapping in Custom Modules”import-tree.map (path: { imports = [ path ]; }) ./modulesTracing Discovered Files
Section titled “Tracing Discovered Files”import-tree.map lib.traceVal ./modulesThis prints each discovered path during evaluation — useful for debugging.
Composing Maps
Section titled “Composing Maps”Multiple .map calls compose left-to-right (the first map runs first):
lib.pipe import-tree [ (i: i.map import) # import each .nix file (i: i.map builtins.stringLength) # get the length of each result (i: i.withLib lib) (i: i.leafs ./dir)]Using map Outside Module Evaluation
Section titled “Using map Outside Module Evaluation”When used with .leafs or .pipeTo, .map transforms paths into arbitrary values — not just modules:
# Read all .md files under a directorylib.pipe import-tree [ (i: i.initFilter (lib.hasSuffix ".md")) (i: i.map builtins.readFile) (i: i.withLib lib) (i: i.leafs ./docs)]# => [ "# Title\n..." "# Other\n..." ]