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

[question] Can I use this to override a hook while leaving pre-commit-hooks.yaml alone for my non-nix-using colleagues? #345

Open
MatrixManAtYrService opened this issue Aug 26, 2023 · 3 comments · May be fixed by #496

Comments

@MatrixManAtYrService
Copy link

MatrixManAtYrService commented Aug 26, 2023

I see that there is already an issue for documenting how to "override" a hook. I also want to override a hook, but I think we mean "override" in different ways.

Most of my team doesn't use nix, so they run pre-commit against a .pre-commit-hooks.yaml which I would be frowned at if I deleted and .gitignored as this warning recommends:

pre-commit-hooks.nix: WARNING: Refusing to install because of pre-existing .pre-commit-config.yaml
    1. Translate .pre-commit-config.yaml contents to the new syntax in your Nix file
        see https://github.com/cachix/pre-commit-hooks.nix#getting-started
    2. remove .pre-commit-config.yaml
    3. add .pre-commit-config.yaml to .gitignore

I maintain a flake.nix in my team's repo because I appreciate the determinism, especially when switching between machines. This comes with certain headaches like this one. Since charliermarsh/ruff-pre-commit breaks on NixOS but works for my non-nix coworkers, I'd like to do the following.

A: contribute a ruff pre-commit hook to pre-commit-hooks.nix
B: configure pre-commit-hooks.nix to run the nix-friendly hook instead of charliermarsh/ruff-pre-commit, but otherwise conform to the existing hooks
C: commit this configuration to my repo in a way that does not break my non-nix coworker's workflows

So when I say "override" I mean:

leave the traditional pre-commit configuration intact but have pre-commit-hooks.nix "take over" for certain hooks.

Can I get some advice on whether pre-commit-hooks.nix is capable of supporting B and C? If so, how would I configure it?

@MatrixManAtYrService
Copy link
Author

A more general application of this pattern would be to override cases like this:

    - repo: local
      hooks:
        - id: foo
          language: system
          entry: python ./somescript.py

So that you can map them to declared environments, rather than using whatever pre-commit comes up with for "system"

@Dich0tomy
Copy link

Dich0tomy commented Jul 14, 2024

Has anyone found a solution for this already? I don't want to necessarily overwrite, but at least keep the existing .pre-commit-hook.yaml for non-nix collaborators

@roberth
Copy link
Contributor

roberth commented Jul 14, 2024

It's currently hardcoded, but I suppose with some hacking (on this repo) the location could be turned into an option

ln -fs ${configFile} src/.pre-commit-config.yaml

I think you can pass an alternate config location to pre-commit as well.

diefans added a commit to bettermarks/git-hooks.nix that referenced this issue Sep 26, 2024
This fixes cachix#345, by adding a `configFile` option to change the default
(`.pre-commit-config.yaml`) and so enables the parallel usage of devenv
and non-devenv maintained pre-commit hooks.
@diefans diefans linked a pull request Sep 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants