NiXium-org / NiXium

Open-Source Infrastructure as Code Management Solution for Multiple Systems designed to be reliable in mission-critical tasks on paranoid and high-security environment.
European Union Public License 1.2
6 stars 2 forks source link

Use statix to capture and fix anti-patterns in all the nix files #65

Open TanvirOnGH opened 1 week ago

TanvirOnGH commented 1 week ago

ref: statix See statix -h for a full list of options. Can be configured with statix.toml per project. All lints are enabled by default. To generate a minimal config:

statix dump > statix.toml

To highlight the anti-patterns in your nix code:

statix check

It recursively finds nix files and raises lints for the provided directory.

To fix several such occurrences:

statix fix
TanvirOnGH commented 1 week ago

Github Actions Workflow

Add the following to your project's .github/workflows/statix.yml:

name: Lint with statix
on:
  push:
    paths:
      - "**.nix"
  workflow_dispatch:

jobs:
  statix:
    name: Lint code
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: cachix/install-nix-action@v25
      - uses: cachix/cachix-action@v14
        with:
          name: statix
      - uses: jocelynthode/statix-action@master

The workflow runs automatically on every push to the repository that includes changes to .nix files.

It can also be triggered manually via the "Workflow dispatch" feature in the GitHub Actions tab of the repository. It provides flexibility to run the formatting process as needed outside of the regular push events.

Possible to apply fixes with statix fix and push it with something like:

- name: Push changes
  uses: stefanzweifel/git-auto-commit-action@v4
  with:
    commit_message: "chore: linting nix code with deadnix"

or for PR/MR we could use something like peter-evans/create-pull-request.

TanvirOnGH commented 1 week ago

I'm using this workflow: statix.yml