nix-homelab
nix-homelab copied to clipboard
Add deadnix to detect unused variable bindings in Nix files
Description
Add deadnix integration to automatically scan .nix files for dead code (unused variable bindings) in the project.
Motivation As Nix configurations evolve, unused variable bindings can accumulate, making the codebase harder to maintain and understand. Automated detection of dead code helps maintain code quality and prevents confusion about which variables are actually being used.
Proposed Solution Integrate deadnix into the development workflow by:
- Adding deadnix to the development environment
- Creating a mechanism to run deadnix checks (pre-commit hooks, CI, or both)
- Establishing a policy for handling dead code detection (block builds or warn)
Suggested Implementation
Add deadnix to flake.nix or shell.nix development dependencies:
# In flake.nix devShells section or shell.nix
pkgs.mkShell {
buildInputs = [
pkgs.deadnix
# ... other dependencies
];
}
Option 1: Pre-commit Hook (using pre-commit framework)
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: deadnix
name: deadnix
entry: deadnix --fail
language: system
files: \.nix$
Option 2: GitHub Actions CI Check
# .github/workflows/nix-checks.yml
name: Nix Code Quality
on:
pull_request:
paths:
- '**.nix'
push:
branches: [main]
paths:
- '**.nix'
workflow_dispatch:
jobs:
deadnix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
- name: Check for dead code
run: |
nix profile install nixpkgs#deadnix
deadnix --fail .
Acceptance Criteria
- deadnix is available in the development environment
- Developers can run deadnix checks locally
- Dead code detection is automated (via pre-commit hooks and/or CI)
- Clear documentation on how to use deadnix
- Policy defined: should dead code block merges or just warn?
Additional Notes
- deadnix can be run with
--editflag to automatically remove dead code - Consider running an initial scan and cleanup in a separate PR before enforcing checks
- deadnix supports
--no-lambda-argand--no-lambda-pattern-namesflags for specific use cases - May want to add deadnix check to existing CI workflow rather than creating a new one