flake-parts-builder
What is flake-parts-builder?
Section titled “What is 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:
- Bootstraps flake-parts-builder from
./flake-parts. - Auto-loads Nix modules from
./flake-parts. - Reads each part’s
./flake-parts/<part>/_meta/directory as flake-file config.
Adding parts
Section titled “Adding parts”nix run github:vic/flake-parts-builder/write-meta -- add --write-meta --parts systems,treefmt $PWDImportant: Use
github:vic/flake-parts-builder/write-metauntil 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
addsubcommand. Theinitsubcommand overwritesflake.nix, which is managed by flake-file.
Regenerate after adding parts
Section titled “Regenerate after adding parts”nix run ".#write-flake"nix flake checkHow _meta/ works
Section titled “How _meta/ works”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.