cachix / git-hooks.nix

Seamless integration of https://pre-commit.com git hooks with Nix.
Apache License 2.0
526 stars 154 forks source link

Redesign module options #196

Closed domenkozar closed 7 months ago

domenkozar commented 1 year ago

Something like:

{
  git.hooks.pre-commit.shellcheck.enable = true;
  git.hooks.push.shellcheck.enable = true;
}

cc @roberth

roberth commented 1 year ago
-  git.hooks.pre-commit.shellcheck.enable = true;
+  hooks.pre-commit.shellcheck.enable = true;

This way devenv can import it using git = mkOption { type = submodule pre-commit-hooks-module; } and the flake parts module can import it in its own way. The latter needs to be explicit about the implementation in the prefix and pre-commit.settings.git.hooks would kinda suck. Isn't this the status quo actually?

Anyway, another nice thing would be to do

{
options.hooks = mkOption {
  type = submodule {
    freeformType = types.attrsOf hookModule;
  };
};
}

and then declare built in hooks as something like

{
options.hooks.nixpkgs-fmt = mkOption {
  type = submodule {
    imports = [ hookModule ];
    options.some-setting = mkOption ...;
  };
};
}

thereby adding the individual hooks in the option docs, and removing the need for a separate settings namespace.

roberth commented 1 year ago

The redesigned pattern should have a package option, so the tools indirection becomes unnecessary, and overlays can be avoided. Refs https://github.com/cachix/pre-commit-hooks.nix/issues/204#issuecomment-1334165738

domenkozar commented 1 year ago

Eventually I'd like the interface to be:

  hooks.ormolu.enable = true;
  hooks.ormolu.package = pkgs.ormolu;
  hooks.ormolu.settings.defaultExtensions = [ "lhs" "hs" ];
domenkozar commented 7 months ago

Merged to master!