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] forcing replacement of GIT_WC/.pre-commit-config.yaml #368

Closed
roman opened this issue Nov 2, 2023 · 1 comment · Fixed by #573
Closed

[question] forcing replacement of GIT_WC/.pre-commit-config.yaml #368

roman opened this issue Nov 2, 2023 · 1 comment · Fixed by #573

Comments

@roman
Copy link

roman commented Nov 2, 2023

Hello there,

I'm running various flake.nix inside a large monorepo, and each of these flake.nix configures a pre-commit-hook for that specific sub-project of the monorepo.

I would like the hook to override the .pre-commit-config.yaml of other flakes whenever I do a nix develop, is there a way to do this? And if not, would you be willing to support it?

@jokatzke
Copy link

jokatzke commented Mar 4, 2025

I have worked around this issue by overriding the shellHook phase of pre-commit.devShell to first delete the .pre-commit-config.yaml file at the git root. Maybe this is also useful to you? :)

(config.pre-commit.devShell.overrideAttrs (old: {
  shellHook =
    let
      # delete the local `.pre-commit-config.yaml` file before creating it again.
      # this prevents the pre-commit hooks from updating when loading a development
      # environment of a sub-project
      delete-old-pre-commit-config = pkgs.writeShellScriptBin "delete-old-pre-commit-config" ''
        export root=$(${lib.getExe pkgs.git} rev-parse --show-toplevel)
        ${lib.getExe' pkgs.toybox "rm"} -f $root/.pre-commit-config.yaml
      '';
    in
    ''
      ${lib.getExe delete-old-pre-commit-config}
    ''
    + old.shellHook;
}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants