2
2
3
3
> Helper functions for import of [ Nixpkgs module system] ( https://nix.dev/tutorials/module-system/ ) modules under a directory recursively
4
4
5
- Module class agnostic; can be used for NixOS, nix-darwin, home-manager, flake-parts, NixVim.
5
+ - Flake callable; Easy to use, intuitive for the most common use case: ` inputs.import-tree ./modules `
6
+ - Module class agnostic; can be used for NixOS, nix-darwin, home-manager, flake-parts, NixVim.
7
+ - Can be used outside flakes as a dependencies-free lib; Just import our ` ./default.nix ` .
8
+ - Can be used to list other file types, not just ` .nix ` . See ` .initFilter ` , ` .files ` API.
9
+ - Extensible API. import-tree objects are customizable. See ` .addAPI ` .
6
10
7
11
## Quick Usage (with flake-parts)
8
12
@@ -29,7 +33,9 @@ you can use the import-tree API (read below for more).
29
33
30
34
## Ignored files
31
35
32
- Paths that have a component that begins with an underscore are ignored.
36
+ By default, paths having a component that begins with an underscore (` /_ ` ) are ignored.
37
+
38
+ This can be changed by using ` .initFilter ` API.
33
39
34
40
<details >
35
41
<summary >
@@ -177,6 +183,8 @@ Or, in a simpler but less readable way:
177
183
(import-tree.filter (lib.hasInfix ".mod.")).filter (lib.hasSuffix "default.nix") ./some-dir
178
184
```
179
185
186
+ See also ` import-tree.initFilter ` .
187
+
180
188
### ` import-tree.match ` and ` import-tree.matchNot `
181
189
182
190
` match ` takes a regular expression. The regex should match the full path for the path to be selected. Matching is done with ` builtins.match ` .
@@ -297,6 +305,37 @@ import-tree.leafs
297
305
Returns a fresh import-tree with empty state. If you previously had any path, lib, filter, etc,
298
306
you might need to set them on the new empty tree.
299
307
308
+ ### ` import-tree.initFilter `
309
+
310
+ * Replaces* the initial filter which defaults to: Include files with ` .nix ` suffix and not having ` /_ ` infix.
311
+
312
+ _ NOTE_ : initFilter is non-accumulating and is the * first* filter to run before those accumulated via ` filter ` /` match ` .
313
+
314
+ You can use this to make import-tree scan for other file types or change the ignore convention.
315
+
316
+ ``` nix
317
+ # import-tree.initFilter : (path -> bool) -> import-tree
318
+
319
+ import-tree.initFilter (p: lib.hasSuffix ".nix" p && !lib.hasInfix "/ignored/") # nix files not inside /ignored/
320
+ import-tree.initFilter (lib.hasSuffix ".md") # scan for .md files everywhere, nothing ignored.
321
+ ```
322
+
323
+ ### ` import-tree.files `
324
+
325
+ A shorthand for ` import-tree.leafs.result ` . Returns a list of matching files.
326
+
327
+ This can be used when you don't want to import the tree, but just get a list of files from it.
328
+
329
+ Useful for listing files other than ` .nix ` , for example, for passing all ` .js ` files to a minifier:
330
+
331
+ _ TIP_ : remember to use ` withLib ` when * not* using import-tree as a module import.
332
+
333
+ ``` nix
334
+ # import-tree.files : [ <list-of-files> ]
335
+
336
+ ((import-tree.withLib lib).initFilter (lib.hasSuffix ".js")).files # => list of all .js files
337
+ ```
338
+
300
339
### ` import-tree.result `
301
340
302
341
Exactly the same as calling the import-tree object with an empty list ` [ ] ` .
0 commit comments