Nixpkgs-fmt bot?

I’m curious if there’s interest in a nixpkgs-fmt bot similar to rmcgibbo’s lovely nixpkgs-review bot?

It doesn’t seem like it’d be that hard to set up. It’d be nice to avoid bikeshedding and get people immediate feedback on their PRs, esp for new contributors.

1 Like

It’s possible to setup a github action as simple as this with Makes’ formatNix

# /path/to/nixos/nixpkgs/makes.nix
  formatNix.enable = true;
  formatNix.targets = [ "/" ]; # Entire project
# /path/to/nixos/nixpkgs/.github/workflows/format.yml
name: nixpkgs-fmt
on: [push, pull_request]
    runs-on: ubuntu-latest
    - uses: actions/checkout@v2
    - uses: docker://
        args: m . /formatNix

when run locally it formats automatically, and on CI it fails if not properly formatted


Although I would love to be in a place eventually where it becomes a CI check I imagine that may not be feasible in the short term. We may need to take baby steps to get there. Maybe like a bot that suggests code changes in a comment? It all depends what kind of appetite people have for a tool like this.

People interested in this should probably join the RFC discussion [RFC 0101] Nix formatting by happysalada · Pull Request #101 · NixOS/rfcs · GitHub


I don’t think that is any easier than a CI check that tells you: run ``nix-shell -p nixpkgs-fmt --command “nixpkgs-fmt $FILE”

Is it nixpkgs-fmt or nixfmt ?
Which is the true formatter ?


nixfmt development is dead since 2 years and it enforces very short lines with unecessary new lines at odd places. For example this creates very often a new line after url = because the url following it is to long. That doesn’t help though to make the code more readable.

The true formatter is you, the developer.

I tried online demos of them few days ago.
nixfmt is buggy, at least when making indentation in multi line strings, nixpkgs-fmt leaves the code almost untouched: I wanted them to format ugly code dumped by Expr::show(), and nixpkgs-fmt kept all the 1000+ character lines, excessive brackets, etc

1 Like