This tutorial explains how to check formatting on GitHub Actions using treefmt-nix.
Add a treefmt-nix configuration
Section titled “Add a treefmt-nix configuration”Some of the flake templates, including treefmt, integrates treefmt-nix out of the box. You don't have to add a configuration in this case.
Otherwise, please add a configuration to your flake manually by consulting the documentation. They also provide a flake-parts module, which you can use to set up the thing more easily.
Once set up, your project should support reformatting the entire project by running the following command:
nix fmtOn CI, you can run the following command to check formatting without making modifications:
nix build ".#checks.$(nix eval --expr builtins.currentSystem --impure --raw).treefmt"Add a GitHub workflow for running the check
Section titled “Add a GitHub workflow for running the check”Initialize the template from the root directory of the project:
Terminal window nix flake init -t github:akirak/flake-templates#metaAdjust the
.github/workflows/nix-format.ymlfile to match your project requirements. In particular, you may have to tweak the triggers (inonsection).
With the renovate configuration shipped by the template, the actions will be automatically updated.