Examples
flake-parts Module Tree
Section titled “flake-parts Module Tree”{ inputs.import-tree.url = "github:vic/import-tree"; inputs.flake-parts.url = "github:hercules-ci/flake-parts";
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules);}NixOS Configuration
Section titled “NixOS Configuration”{ import-tree, ... }: { imports = [ (import-tree ./modules) ];}Multiple Directories
Section titled “Multiple Directories”import-tree [ ./base-modules ./host-specific ./shared ]Filter by Convention
Section titled “Filter by Convention”Only import files tagged with a +feature convention:
import-tree.filter (lib.hasInfix "+networking") ./modulesRegex-Based Selection
Section titled “Regex-Based Selection”import-tree.match ".*/[a-z]+_[a-z]+\.nix" ./modulesPipeline Style
Section titled “Pipeline Style”lib.pipe import-tree [ (i: i.filter (lib.hasInfix "/desktop/")) (i: i.map lib.traceVal) (i: i ./modules)]Non-Nix File Discovery
Section titled “Non-Nix File Discovery”lib.pipe import-tree [ (i: i.initFilter (lib.hasSuffix ".json")) (i: i.map builtins.readFile) (i: i.map builtins.fromJSON) (i: i.withLib lib) (i: i.leafs ./config)]# => list of parsed JSON objectsPre-Configured Tree for a Library
Section titled “Pre-Configured Tree for a Library”let my-tree = lib.pipe import-tree [ (i: i.addPath ./modules) (i: i.addAPI { desktop = self: self.filter (lib.hasInfix "/desktop/"); server = self: self.filter (lib.hasInfix "/server/"); all = self: self; }) ];in { # Use the desktop subset imports = [ my-tree.desktop ];
# Or import everything # imports = [ my-tree.all ];}Counting Files
Section titled “Counting Files”(import-tree.withLib lib).pipeTo builtins.length ./modulesMixing with Manual Imports
Section titled “Mixing with Manual Imports”{ imports = [ (import-tree ./auto-modules) # auto-discovered ./manual/special-case.nix # manual import ];}Using with addPath and result
Section titled “Using with addPath and result”let tree = import-tree.addPath ./core; extended = tree.addPath ./extras;inextended.result