Skip to content

Overview

import-tree is a Nix library that recursively discovers files in a directory tree and produces a list of Nix module imports. Instead of manually listing every module in your imports = [ ... ], you point import-tree at a directory and it does the rest.

It is a dependency-free, single-file library that works as a flake or a plain import.

Given a directory tree:

modules/
networking.nix
desktop/
sway.nix
waybar.nix
_helpers/
utils.nix

Calling import-tree ./modules produces a module whose imports contain:

  • ./modules/networking.nix
  • ./modules/desktop/sway.nix
  • ./modules/desktop/waybar.nix

The _helpers/ directory is skipped because paths containing /_ are ignored by default.

Universal

Works with NixOS, nix-darwin, home-manager, flake-parts, NixVim — any Nix module system. Quick Start

Composable Filters

Chain .filter, .filterNot, .match, .matchNot to select exactly the files you need. Filtering Guide

Transformations

Use .map to transform discovered paths — wrap in modules, read contents, or anything else. Mapping Guide

Extensible API

Build domain-specific APIs with .addAPI — create named presets, feature flags, module sets. Custom API Guide

Non-Module Usage

Use .leafs and .files outside module evaluation to get raw file lists for any purpose. Outside Modules

Dendritic Pattern

Purpose-built for the Dendritic pattern where every file is a self-contained module. Dendritic Pattern

Contribute Community Sponsor