git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

All rust hooks fail in repositories with multiple workspaces

Open lmbollen opened this issue 4 months ago • 2 comments

My repository contains multiple cargo workspaces, but all current rust hooks (rustfmt , cargo-check and clippy) assume the root to contain a Cargo.toml.

For some hooks you can set manifest-path to point to a Cargo.toml, but this does not solve my problem because I have not one, but multiple workspaces.

Would there be opposition to change manifest-path to manifest-paths (this would ofcourse be an API change....) and allow the user to specify a list of Cargo.toml files?

lmbollen avatar Aug 18 '25 12:08 lmbollen

Would there be opposition to change manifest-path to manifest-paths (this would ofcourse be an API change....) and allow the user to specify a list of Cargo.toml files?

No, this isn't the right place to add workspace complications.

  1. manifest-path maps directly to the CLI option, so manifest-paths wouldn't fit the pattern.
  2. This would introduce incomplete multi-workspace support. For example, someone might want different settings per workspace.
  3. This won't work with nix flake check.

The way to solve this is to use separate hooks per workspace and configure the files regex to run them against the appropriate workspace.

Until something like #593 lands, you'll have to redefine the hook definitions. You'll also have to stick with nix develop -c "pre-commit run".

sandydoo avatar Aug 18 '25 19:08 sandydoo

Thanks for the quick response :).

Am I correct that #593 allows you to create multiple instances of a hook? Because indeed that + the manifest-path option would then probably solve my issue.

So far I've tried to make a custom hook to call rustfmt directly which seemed to work modulo the fact that there were formatting differences with calling through cargo. For clippy I tried a similar approach with clippy-driver with no luck.

Unfortunately I'm not very fluent in Nix and this seems like a huge task, otherwise Id take a stab to forward this cause. So I'll patiently wait for the support.

lmbollen avatar Aug 19 '25 07:08 lmbollen