Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixpkgs-fmt should support excluding files #191

Open
lovesegfault opened this issue Mar 26, 2020 · 6 comments
Open

nixpkgs-fmt should support excluding files #191

lovesegfault opened this issue Mar 26, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@lovesegfault
Copy link

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 lovesegfault added enhancement New feature or request needs triage labels Mar 26, 2020
@zimbatm
Copy link
Member

zimbatm commented Mar 26, 2020

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.

@lovesegfault
Copy link
Author

That works!

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

@zimbatm
Copy link
Member

zimbatm commented Mar 27, 2020

yeah agreed, this issue is not solved

@bhipple
Copy link
Contributor

bhipple commented Mar 28, 2020

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

@camelpunch
Copy link

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

@zoechi
Copy link

zoechi commented Jan 11, 2024

.ignore and .gitignore didn't work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants