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
48 changes: 40 additions & 8 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
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 @@ -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