Import all nix files in a directory tree. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic inputs

readme

+15 -20
+15 -20
README.md
··· 22 22 23 23 ๐ŸŒณ Works with NixOS, nix-darwin, home-manager, flake-parts, NixVim, etc.\ 24 24 ๐ŸŒฒ Callable as a deps-free Flake or nix lib.\ 25 - ๐ŸŒด API for listing custom file types with filters and transformations.\ 26 - ๐ŸŒต Extensible: add your own API methods to tailor import-tree objects.\ 27 - ๐ŸŽ„ No dependencies outside flakes: just `import ./default.nix`.\ 25 + ๐ŸŒด Sensible defaults and configurable behaviour.\ 26 + ๐ŸŒต API for listing custom file types with filters and transformations.\ 27 + ๐ŸŽ„ Extensible: add your own API methods to tailor import-tree objects.\ 28 28 ๐ŸŒฟ Useful on [Dendritic Pattern](https://github.com/mightyiam/dendritic) setups.\ 29 29 ๐ŸŒฑ [Growing](https://github.com/search?q=language%3ANix+import-tree&type=code) [community](https://vic.github.io/dendrix/Dendrix-Trees.html) [adoption](https://github.com/vic/flake-file) 30 30 ··· 126 126 ((import-tree.map lib.traceVal).filter (lib.hasInfix ".mod.")) ./modules 127 127 ``` 128 128 129 - ##### `import-tree.filter` and `import-tree.filterNot` 129 + ##### ๐ŸŒฒ `import-tree.filter` and `import-tree.filterNot` 130 130 131 131 `filter` takes a predicate function `path -> bool`. Only files with suffix `.nix` are candidates. 132 132 ··· 136 136 137 137 Multiple filters can be combined, results must match all of them. 138 138 139 - ##### `import-tree.match` and `import-tree.matchNot` 139 + ##### ๐ŸŒณ `import-tree.match` and `import-tree.matchNot` 140 140 141 141 `match` takes a regular expression. The regex should match the full path for the path to be selected. Matching is done with `builtins.match`. 142 142 ··· 146 146 147 147 Multiple match filters can be added, results must match all of them. 148 148 149 - ##### `import-tree.map` 149 + ##### ๐ŸŒด `import-tree.map` 150 150 151 151 `map` can be used to transform each path by providing a function. 152 152 ··· 166 166 # => list of contents of all files. 167 167 ``` 168 168 169 - ##### `import-tree.addPath` 169 + ##### ๐ŸŒต `import-tree.addPath` 170 170 171 171 `addPath` can be used to prepend paths to be filtered as a setup for import-tree. 172 172 ··· 175 175 import-tree [./vendor ./modules] 176 176 ``` 177 177 178 - ##### `import-tree.addAPI` 178 + ##### ๐ŸŽ„ `import-tree.addAPI` 179 179 180 180 `addAPI` extends the current import-tree object with new methods. 181 181 ··· 187 187 } 188 188 ``` 189 189 190 - ##### `import-tree.withLib` 190 + ##### ๐ŸŒฟ `import-tree.withLib` 191 191 192 192 `withLib` is required prior to invocation of any of `.leafs` or `.pipeTo` when not used as part of a nix modules evaluation. 193 193 ··· 195 195 import-tree.withLib pkgs.lib 196 196 ``` 197 197 198 - ##### `import-tree.pipeTo` 198 + ##### ๐ŸŒฑ `import-tree.pipeTo` 199 199 200 200 `pipeTo` takes a function that will receive the list of paths. 201 201 ··· 203 203 import-tree.pipeTo lib.id # equivalent to `.leafs` 204 204 ``` 205 205 206 - ##### `import-tree.leafs` 206 + ##### ๐Ÿƒ `import-tree.leafs` 207 207 208 208 `leafs` takes no arguments, it is equivalent to calling `import-tree.pipeTo lib.id`. 209 209 ··· 211 211 import-tree.leafs 212 212 ``` 213 213 214 - ##### `import-tree.new` 214 + ##### ๐ŸŒฒ `import-tree.new` 215 215 216 216 Returns a fresh import-tree with empty state. 217 217 218 - ##### `import-tree.initFilter` 218 + ##### ๐ŸŒณ `import-tree.initFilter` 219 219 220 220 *Replaces* the initial filter which defaults to: Include files with `.nix` suffix and not having `/_` infix. 221 221 ··· 224 224 import-tree.initFilter (lib.hasSuffix ".md") 225 225 ``` 226 226 227 - ##### `import-tree.files` 227 + ##### ๐ŸŒด `import-tree.files` 228 228 229 229 A shorthand for `import-tree.leafs.result`. Returns a list of matching files. 230 230 ··· 237 237 ] 238 238 ``` 239 239 240 - ##### `import-tree.result` 240 + ##### ๐ŸŒต `import-tree.result` 241 241 242 242 Exactly the same as calling the import-tree object with an empty list `[ ]`. 243 243 ··· 262 262 263 263 ### Sharing pre-configured subtrees of modules 264 264 265 - <details> 266 - <summary> 267 - 268 265 Since the import-tree API is _extensible_ and lets you add paths or 269 266 filters at configuration time, configuration-library authors can 270 267 provide custom import-tree instances with an API suited for their 271 268 particular idioms. 272 269 273 270 @vic is using this on [Dendrix](https://github.com/vic/dendrix) for [community conventions](https://github.com/vic/dendrix/blob/main/dev/modules/community/_pipeline.nix) on tagging files. 274 - 275 - </summary> 276 271 277 272 This would allow us to have community-driven *sets* of configurations, 278 273 much like those popular for editors: spacemacs/lazy-vim distributions.