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.
Initialize
Section titled “Initialize”mkdir example && cd examplenix flake init -t github:denful/den#flake-parts-modulesnix flake update dennix flake shownix flake check -LProject Structure
Section titled “Project Structure”flake.nixmodules/ 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.nixKey points:
- A custom class file under
modules/classes/registers its class withden.classes.<name> = { };, imports the third-partyflakeModule, then forwards content into theflake-partsscope with aroutepolicy fromden.lib.policy. (packages.nixreuses Den’s built-inpackagesclass instead.) - Classes are wired into the
flake-partsscope viaden.schema.flake-parts.includes, so any module can contribute newperSystemclasses.
Next Steps
Section titled “Next Steps”- Read flake.parts Documentation for more
perSystemmodules.