feat: integrate with nix fmt - #743
Open
Malix-Labs wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLOSES: #287
Description
This PR provides built-in integration with
nix fmtby exposing aformatterpackage that wraps the configured pre-commit hooks.Changes
modules/pre-commit.nix: Addformatterpackage option creating apre-commit-fmtwrapper script. It handles:--all-filesunder$PRJ_ROOT) when called without arguments.--files "$@") when positional arguments are passed bynix fmt.1) into success (0) while still propagating real errors.nix/run.nix: Exposeformatteron the returned derivation for standalone flake setups (self.checks.${system}.pre-commit-check.formatter).flake-module.nix: Addpre-commit.formatteroption and setformatter = lib.mkDefault cfg.settings.formatter;to automatically configurenix fmtinflake-parts.template/flake.nix: Update template with comments notingnix fmtworks out of the box.README.md: Update the flake example to usepre-commit-check.formatterdirectly instead of manual boilerplate.nix/tests/hook-config.nix: Add assertions to ensureformatteris a valid derivation.