Skip to content

feat(nix): Add comprehensive Nix pre-commit hooks#23

Merged
aRustyDev merged 2 commits intomainfrom
feature/nix-hooks
Jul 8, 2025
Merged

feat(nix): Add comprehensive Nix pre-commit hooks#23
aRustyDev merged 2 commits intomainfrom
feature/nix-hooks

Conversation

@aRustyDev
Copy link
Owner

Summary

This PR introduces a comprehensive set of pre-commit hooks for Nix development, providing validation, formatting, and linting capabilities for Nix files, flakes, darwin configurations, and home-manager setups.

New Hooks Added

Core Testing Hooks

  1. nix-flake-check - Validates flake.nix files using nix flake check
  2. nix-build-check - Tests Nix builds for both flakes and legacy expressions
  3. nix-darwin-check - Validates nix-darwin configurations (Darwin-only)
  4. nix-home-manager-check - Tests home-manager configurations

Code Quality Hooks

  1. nix-fmt - Formats Nix files (supports nixpkgs-fmt, alejandra, nixfmt)
  2. nix-lint - Lints Nix files using statix and optionally deadnix

Key Features

  • ✅ Automatic tool installation if missing
  • ✅ Support for both flakes and legacy Nix expressions
  • ✅ Clear, actionable error messages
  • ✅ Configurable behavior via environment variables
  • ✅ Platform-aware (e.g., darwin-check only runs on macOS)
  • ✅ Follows existing repository patterns and conventions

Configuration Examples

repos:
  - repo: https://github.com/aRustyDev/pre-commit-hooks
    rev: main
    hooks:
      - id: nix-fmt
        args: [--formatter=alejandra]
      - id: nix-lint
        args: [--with-deadnix]
      - id: nix-flake-check
      - id: nix-build-check

Testing

All hooks have been tested with sample Nix configurations included in tests/nix/fixtures/.

Closes Issues

🤖 Generated with Claude Code

aRustyDev and others added 2 commits March 19, 2025 00:17
This commit introduces six new pre-commit hooks for Nix development:

1. **nix-flake-check**: Validates flake.nix files using `nix flake check`
2. **nix-build-check**: Tests Nix builds for both flakes and legacy expressions
3. **nix-darwin-check**: Validates nix-darwin configurations (Darwin-only)
4. **nix-home-manager-check**: Tests home-manager configurations
5. **nix-fmt**: Formats Nix files (supports nixpkgs-fmt, alejandra, nixfmt)
6. **nix-lint**: Lints Nix files using statix and optionally deadnix

All hooks include:
- Automatic tool installation if missing
- Support for both flakes and legacy Nix
- Clear error messages
- Configurable behavior via environment variables

Also includes test fixtures for validating hook functionality.

Closes #15, Closes #16, Closes #17, Closes #18, Closes #19, Closes #20, Closes #21

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@aRustyDev aRustyDev merged commit c16a199 into main Jul 8, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant