nixpkgs-fmt
nixpkgs-fmt copied to clipboard
nixpkgs-fmt should support excluding files
Is your feature request related to a problem? Please describe.
In our repo we have a few autogen'd Nix files, such as Cargo.nix
from crate2nix
and sources.nix
from niv
. These aren't properly formatted, but I don't want our CI to fail because of that.
Describe the solution you'd like
I want to be able to ignore certain files in my nixpkgs-fmt
call. For example nixpkgs-fmt . --not "Cargo.nix"
Describe alternatives you've considered Here's my ugly alternative:
find . -iname "*.nix" \
-not -path ./Cargo.nix \
-not -path ./nix/sources.nix \
-exec nixpkgs-fmt --check {} +
Hey @lovesegfault, try adding a .ignore
file with the pattern to exclude. It should be in the same form as the .gitignore
files. We use the ignore
crate which seems to be using that file but haven't test it myself.
That works!
I'd still like for this to be doable from the cli, though. I'm not keen on these special files :/
yeah agreed, this issue is not solved
Another standard technique is being able to put something like # yapf: disable
or // clang-format: disable
as a comment in the header of the file.
For nixpkgs specifically, the nixpkgs-update
bot has some support for reading these type of comments and leaving a file alone if they contain them:
https://github.com/ryantm/nixpkgs-update/blob/master/src/Blacklist.hs#L117
The README says you can use --exclude GLOB
, but this doesn't appear to work:
$ nixpkgs-fmt --exclude deps.nix
error: Found argument '--exclude' which wasn't expected, or isn't valid in this context
USAGE:
nixpkgs-fmt [FLAGS] [OPTIONS] [FILE]...
For more information try --help
.ignore
and .gitignore
didn't work for me