-
Notifications
You must be signed in to change notification settings - Fork 174
Supported pre-commit hook #31
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
Comments
As an aside question, is there a way to integrate local hooks ? |
tldr; supported hooks: requires change, local hooks: already possible supported hooksLooks like you want to add hooks from pre-commit's standard repo https://github.com/pre-commit/pre-commit-hooks This possibility is not properly exposed through an option yet, but it can be added via the local hooksThe latest version has been simplified from what it used to be and basically only works exclusively via the local hooks feature. |
Supported hooksIf I add to the
How can I ensure that the hook is pinned (and goes in a binary cache) ? The integrity and self-encapsulation of |
Precisely those are possibly most elegantly addressed in an [*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true |
I managed to get the
Ideal because it's now self-contained within the Nix store, not ideal because you have to replicate the hook's settings. |
It took me a while to figure out how to use pre-commit = {
hooks = {
nil.enable = true; # HACK: some hook needs to be enabled for pre-commit to enable itself - but will be overwritten anyways
};
rawConfig = {
repos = [
{
"repo" = "https://github.com/codingjoe/relint";
"rev" = "1.2.1";
"hooks" = [
{ "id" = "relint"; "exclude" = ''...''; }
];
}
];
};
}; |
I ended up writing this to make them all available in the same vein: pre-commit.settings.hooks = lib.trivial.pipe source [
(pkg: "${pkg.src}/.pre-commit-hooks.yaml")
fromYAMLFile
(builtins.map (hook: lib.attrsets.nameValuePair hook.id hook))
builtins.listToAttrs
(builtins.mapAttrs (_: hook: lib.trivial.pipe hook [
(hook: hook // {enable = false; entry = "${source}/bin/${hook.entry}";})
# stages are excluded to support setting pre-commit.settings.default_stages
(hook: builtins.removeAttrs hook ["id" "stages"])
(builtins.mapAttrs (_: lib.mkDefault))
]))
]; where fromYAMLFile = input_f:
lib.trivial.pipe input_f [
(file: "remarshal -if yaml -i \"${file}\" -of json -o \"$out\"")
(pkgs.runCommand "from-yaml" {nativeBuildInputs = [pkgs.remarshal];})
lib.trivial.importJSON
]; In a separate module I then enable and override the ones I want: pre-commit.settings.default_stages = ["pre-push" "manual"];
pre-commit.settings.hooks = {
check-merge-conflict.enable = true;
check-merge-conflict.raw.args = ["--assume-in-merge"];
no-commit-to-branch.enable = true;
no-commit-to-branch.raw.args = ["--branch" "trunk"];
trailing-whitespace.enable = true;
}; There's probably something horribly wrong with this approach ( |
The built-in pre-commit hooks should now be exposed. See #401. |
How can I integrate the supported hook from pre-commit such as
end-of-file-fixer
ortrailing-whitespace
into pre-commit-hooks.nix ?The text was updated successfully, but these errors were encountered: