Skip to content

feat: integrate with nix fmt - #743

Open
Malix-Labs wants to merge 1 commit into
cachix:masterfrom
Malix-Labs:integrate-nix-fmt
Open

feat: integrate with nix fmt#743
Malix-Labs wants to merge 1 commit into
cachix:masterfrom
Malix-Labs:integrate-nix-fmt

Conversation

@Malix-Labs

Copy link
Copy Markdown

CLOSES: #287

Description

This PR provides built-in integration with nix fmt by exposing a formatter package that wraps the configured pre-commit hooks.

Changes

  • modules/pre-commit.nix: Add formatter package option creating a pre-commit-fmt wrapper script. It handles:
    • Formatting all files (--all-files under $PRJ_ROOT) when called without arguments.
    • Formatting specific files (--files "$@") when positional arguments are passed by nix fmt.
    • Re-running to ensure convergence and converting pre-commit's modification exit code (1) into success (0) while still propagating real errors.
  • nix/run.nix: Expose formatter on the returned derivation for standalone flake setups (self.checks.${system}.pre-commit-check.formatter).
  • flake-module.nix: Add pre-commit.formatter option and set formatter = lib.mkDefault cfg.settings.formatter; to automatically configure nix fmt in flake-parts.
  • template/flake.nix: Update template with comments noting nix fmt works out of the box.
  • README.md: Update the flake example to use pre-commit-check.formatter directly instead of manual boilerplate.
  • nix/tests/hook-config.nix: Add assertions to ensure formatter is a valid derivation.

Expose a `formatter` package that wraps `pre-commit run` for use with `nix fmt`.

- Provide `formatter` option in `modules/pre-commit.nix` and inherit it in `run.nix`.
- In `flake-module.nix`, expose `pre-commit.formatter` and set `formatter = lib.mkDefault cfg.settings.formatter;`.
- Handle pre-commit exit codes when files are reformatted so that `nix fmt` succeeds when changes are applied.
- Update template and README documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate with nix fmt

1 participant