nixpkgs-fmt icon indicating copy to clipboard operation
nixpkgs-fmt copied to clipboard

nixpkgs-fmt should support excluding files

Open lovesegfault opened this issue 4 years ago • 6 comments

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 {} +

lovesegfault avatar Mar 26 '20 17:03 lovesegfault

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.

zimbatm avatar Mar 26 '20 17:03 zimbatm

That works!

I'd still like for this to be doable from the cli, though. I'm not keen on these special files :/

lovesegfault avatar Mar 26 '20 17:03 lovesegfault

yeah agreed, this issue is not solved

zimbatm avatar Mar 27 '20 10:03 zimbatm

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

bhipple avatar Mar 28 '20 19:03 bhipple

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

camelpunch avatar Oct 04 '23 14:10 camelpunch

.ignore and .gitignore didn't work for me

zoechi avatar Jan 11 '24 12:01 zoechi