Skip to content

Template: Flake Parts Modules

The flake-parts-modules template demonstrates how to use Den aspects that propagate custom classes into third-party flake-parts perSystem modules.

For demo purposes, the example showcases:

  • perSystem.packages: How to expose flake-parts packages.
  • numtide/devshell: A default devshell extensible by any aspect.
  • numtide/treefmt-nix: A shared formatter configured across aspects.
  • sini/files: Generates README from nix code.
  • nix-community/nix-unit: Write tests directly on aspects.
Terminal window
mkdir example && cd example
nix flake init -t github:denful/den#flake-parts-modules
nix flake update den
nix flake show
nix flake check -L
flake.nix
modules/
den.nix # Hosts, aspects using the classes, and pipeline wiring.
perSystem-from-hosts.nix # Reads flake-parts classes from each host.
pkgs-by-name.nix # Wires drupol/pkgs-by-name-for-flake-parts.
classes/
packages.nix # perSystem.packages.
devshell.nix # numtide/devshell.
treefmt.nix # numtide/treefmt-nix.
files.nix # sini/files.
nix-unit.nix # nix-community/nix-unit.
packages/
hola.nix

Key points:

  • A custom class file under modules/classes/ registers its class with den.classes.<name> = { };, imports the third-party flakeModule, then forwards content into the flake-parts scope with a route policy from den.lib.policy. (packages.nix reuses Den’s built-in packages class instead.)
  • Classes are wired into the flake-parts scope via den.schema.flake-parts.includes, so any module can contribute new perSystem classes.
Contribute Community Sponsor