3 Likes
For importing Nixpkgs module system modules
Yes!, the main use case is importing files (thus the name).
I’ve been using it on dendrix exactly for that. Just like many other people on their config repos.
But I’ve also have a private project where I’ve been using it for listing files that need to be passed into another processor.
(eg, you could list all .css
files and pass them to a minimizer or something).
For example you can do:
# paths for some css processor
lib.pipe import-tree [
(i: i.initFilter (lib.hasSuffix ".css")) # look for .css files. ignore nothing.
(i: i.addPath ./web/styles)
(i: i.withLib lib) # set lib since we are not importing modules.
(i: i.files)
]
# => list of all .css files
Despite the name, import-tree
was always able to just return a list of files (this was being used in tests to check that expected files were returned). But now this capability is also documented as API.
I’ve improved the documentation on the readme to reflect this, and also updated the features section at the top:
- Flake callable; Easy to use, intuitive for the most common use case: inputs.import-tree ./modules
- Module class agnostic; can be used for NixOS, nix-darwin, home-manager, flake-parts, NixVim.
- Can be used outside flakes as a dependencies-free lib; Just import our ./default.nix.
- Can be used to list other file types, not just .nix. See .initFilter, .files API.
- Extensible API. import-tree objects are customizable. See .addAPI.