Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let
(builtins.attrValues enabledHooks);
in
if sortedHooks ? result then
builtins.map (value: value.raw) sortedHooks.result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this change make pre-commit bark on priority?

@leiserfg leiserfg May 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me change it to use localHooks there to be sure, thanks.

sortedHooks.result
else
let
getIds = builtins.map (value: value.id);
Expand All @@ -61,6 +61,33 @@ let

${prettyPrintCycle { indent = " "; } sortedHooks.cycle}
'';
_prekBuiltins =
if usingPrek then
builtins.filter (s: s != "") (builtins.split "\n" (
builtins.readFile (
pkgs.runCommand "prek-builtins.txt"
{
buildInputs = [ cfg.package ];
PREK_HOME = "/tmp/"; # This is to avoid prek trying to create ~/.cache/prek/
}
''${lib.getExe cfg.package} util list-builtins > $out''
)
))
else
[ ];

_is_builtin =
{
package,
name,
...
}:
usingPrek && (package.pname == "pre-commit-hooks") && (builtins.elem name _prekBuiltins);

_partitioned = builtins.partition _is_builtin processedHooks;

builtinHooks = builtins.map (value: builtins.removeAttrs value.raw [ "entry" ]) _partitioned.right;
localHooks = builtins.map (value: value.raw) _partitioned.wrong;

configFile =
performAssertions (
Expand Down Expand Up @@ -439,10 +466,10 @@ in
message = "The `purty` hook has been removed because the project is unmaintained. Consider using `purs-tidy` instead.";
}
{
assertion = usingPrek || (lib.all (hook: !(hook ? priority)) processedHooks);
assertion = usingPrek || (lib.all (hook: !(hook ? priority)) localHooks);
message =
let
hooksWithPriority = lib.filter (hook: hook ? priority) processedHooks;
hooksWithPriority = lib.filter (hook: hook ? priority) localHooks;
hookNames = lib.concatMapStringsSep ", " (hook: hook.id) hooksWithPriority;
in
''
Expand All @@ -455,13 +482,18 @@ in

rawConfig =
{
repos =
[
{
repo = "local";
hooks = processedHooks;
}
];
repos = [
{
repo = "local";
hooks = localHooks;
}
]
++ lib.optionals (builtinHooks != [ ]) [
{
repo = "builtin";
hooks = builtinHooks;
}
];
} // lib.optionalAttrs (cfg.excludes != [ ]) {
exclude = mergeExcludes cfg.excludes;
} // lib.optionalAttrs (cfg.default_stages != [ ]) {
Expand Down