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

Make usable without package distribution

Open roberth opened this issue 5 years ago • 10 comments

pre-commit-hooks.nix in its current form is a package distribution by default; using pinned packages.

Some users (me, #55?) prefer to provide their own packages only, in order to have consistent versions everywhere in a project.

I'd be happy to provide a function to do that, which will work at the module level.

TODO

  • [x] write #60 to make the module system interface a similar as possible
  • [ ] use module system defaults for the default tools
  • [ ] set the default tools with a module that can be enabled (and enable it in run so its behavior remains unchanged)
  • [ ] expose the function in default.nix

In order to improve performance I'd like to move tools into its own attrset, so we can evaluate the spine of default.nix without having to load the pinned nixpkgs. It's even possible to unbreak the move and provide deprecation warnings.

roberth avatar Sep 04 '20 06:09 roberth

If — as a collateral — the code base could be made a little bit easier to grasp, that would be great. I was in sheer despair more than once when working on #52 . — not directly related, though.

blaggacao avatar Sep 04 '20 06:09 blaggacao

Couldn't we just expose pkgs attribute that could be overriden?

domenkozar avatar Oct 06 '20 18:10 domenkozar

Couldn't we just expose pkgs attribute that could be overriden?

In the past we've needed a solution for packages that are packaged with pre-commit-hooks.nix itself. Those did not come from pkgs so to support that, we'd need to expose a way to override tools (or something similar).

So either we forgo packaging hooks or the ability to override those, or we allow tools overrides. The latter can already be done if you wire up the modules yourself, so I think we should make run do nothing more than invoke the module system. Not rearranging arguments into a configuration module is a small breaking change iirc; not too bad.

roberth avatar Oct 06 '20 18:10 roberth

Overriding tools sounds good to me (I forgot we didn't just apply an overlay to pkgs).

domenkozar avatar Oct 07 '20 14:10 domenkozar

I like the way how devshell presents itself as an overlay, this makes it easier to chain things together. Maybe not 100% on topic, but I figured to best comment here nevertheless: https://github.com/numtide/devshell/blob/master/default.nix

What I had in mind:

{
  nixpkgs = import ./nixpkgs-src.nix;
  overlays = [ 
    (import ./overlays/overlay.nix)
    (import ./overlays/pre-commit.nix)
  ];
  pkgs = (import ./devshell-src.nix) { inherit nixpkgs overlays; };
}

(strictly pinning to a single nixpkgs version maybe also helps reduce the closure of the devshell?)

blaggacao avatar Oct 15 '20 16:10 blaggacao

I think people, in general, want to pin the version of tools they use in the pre-commit hooks. That means they need to provide the tools option. This works, even though it is a bit explicit. A problem arises when pre-commit-hooks.nix needs to wrap an external tool with some script (like we do with terraform-fmt). Then the user would need to apply the same wrapper before they pass it into tools. This is not very neat. Maybe we can provide a nixpkgs parameter that the tools will be derived from?

u-quark avatar Dec 31 '20 00:12 u-quark

That sounds good to me.

domenkozar avatar Jan 08 '21 16:01 domenkozar

I think people, in general, want to pin the version of tools they use in the pre-commit hooks. That means they need to provide the tools option. This works, even though it is a bit explicit. A problem arises when pre-commit-hooks.nix needs to wrap an external tool with some script (like we do with terraform-fmt). Then the user would need to apply the same wrapper before they pass it into tools. This is not very neat. Maybe we can provide a nixpkgs parameter that the tools will be derived from?

Note that this is done. What we need are docs to override pkgs and also to override a specific tool.

domenkozar avatar Nov 04 '22 13:11 domenkozar

Note that this is done. What we need are docs to override pkgs and also to override a specific tool.

Can you please explain how this can be done? :pray: The function run still does not take any pkgs argument, only tools, and terraform-fmt does not use terraform coming from tools

sir4ur0n avatar Jan 10 '23 15:01 sir4ur0n

That one isn't possible to override right now - see #196

domenkozar avatar Jan 11 '23 17:01 domenkozar