Hooks
Overview
Section titled “Overview”flake-file provides two hook lists:
flake-file.write-hooks— commands executed afterwrite-flakewritesflake.nix.flake-file.check-hooks— commands executed duringnix flake check.
Each hook is an attrset with an index (for ordering) and a command.
write-hooks
Section titled “write-hooks”Use write-hooks to trigger follow-up actions whenever flake.nix is regenerated — for example, updating a lock file or reformatting.
{ pkgs, ... }: { flake-file.write-hooks = [ { index = 10; exec = "${pkgs.nix}/bin/nix flake update"; } ];}Hooks run in ascending index order, so you can coordinate between modules without knowing the full list.
check-hooks
Section titled “check-hooks”Use check-hooks to add extra validation during nix flake check — for example, checking that a derived file is up to date.
{ pkgs, ... }: { flake-file.check-hooks = [ { index = 10; exec = "${pkgs.my-linter}/bin/my-linter --check ."; } ];}Practical uses
Section titled “Practical uses”- Run
nix flake updateautomatically after regeneration. - Reformat
flake.nixwith a formatter (seeflake-file.formatter). - Validate generated files in CI via check-hooks.
- Trigger allfollow or nix-auto-follow to flatten the lock file.