Pre-commit / git-hooks

pedantix works with git-hooks.nix (formerly known as pre-commit-hooks.nix).

The hooks entry defaults to running pedantix --check on staged *.nix files, so it just fails the commit when something is unformatted, not editing any files.

Using treefmt hook

If you already format with treefmt, you only need to enable the treefmt hook — it runs pedantix as part of the treefmt pass:

{
  imports = [
    inputs.treefmt-nix.flakeModule
    inputs.pedantix.flakeModules.default
    inputs.git-hooks-nix.flakeModule
  ];
  perSystem = _: {
    treefmt.programs.pedantix.enable = true;
    pre-commit.settings.hooks.treefmt.enable = true;
  };
}

Without treefmt

Without treefmt, enable the pedantix hook through the git-hooks flake module:

{
  imports = [
    inputs.git-hooks-nix.flakeModule
    inputs.pedantix.flakeModules.git-hooks
  ];
  perSystem = _: {
    pre-commit.settings.hooks.pedantix.enable = true;
  };
}

Without flake-parts

Use the standalone module directly:

{
  outputs = { self, nixpkgs, git-hooks-nix, pedantix, ... }: {
    checks.x86_64-linux.pre-commit = git-hooks-nix.lib.x86_64-linux.run {
      src = ./.;
      imports = [ pedantix.gitHooksModules.default ];
      hooks.pedantix.enable = true;
    };

    devShells.x86_64-linux.default =
      nixpkgs.legacyPackages.x86_64-linux.mkShell {
        shellHook = self.checks.x86_64-linux.pre-commit.shellHook;
      };
  };
}