Skip to content

flake-parts-builder

flake-parts-builder lets you add or remove templated flake-parts modules (called parts) at any time — not just at project initialisation.

flake-file integrates with it so that each part can also declare its own flake-file inputs via a _meta/ file.

{ inputs, ... }: {
imports = [
(inputs.flake-file.lib.flakeModules.flake-parts-builder ./flake-parts)
];
}

This:

  1. Bootstraps flake-parts-builder from ./flake-parts.
  2. Auto-loads Nix modules from ./flake-parts.
  3. Reads each part’s ./flake-parts/<part>/_meta/ directory as flake-file config.
Terminal window
nix run github:vic/flake-parts-builder/write-meta -- add --write-meta --parts systems,treefmt $PWD

Important: Use github:vic/flake-parts-builder/write-meta until flake-parts-builder#60 is merged. This branch writes each part’s _meta/ file so that flake-file can manage inputs declared by the part.

Warning: Only use the add subcommand. The init subcommand overwrites flake.nix, which is managed by flake-file.

Terminal window
nix run ".#write-flake"
nix flake check

Each part directory may contain a _meta/ subdirectory with Nix files that set flake-file.* options. When the flake-parts-builder module is imported, these files are automatically included in the module evaluation, so the part’s dependencies are declared alongside the part itself.

Contribute Community Sponsor