diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index 0e50e738..b38319c6 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -35,7 +35,32 @@ let (a: b: builtins.elem b.id a.before || builtins.elem a.id b.after) (builtins.attrValues enabledHooks); in - builtins.map (value: value.raw) sortedHooks.result; + if sortedHooks ? result then + builtins.map (value: value.raw) sortedHooks.result + else + let + getIds = builtins.map (value: value.id); + + prettyPrintCycle = opts: cycle: + lib.pipe cycle [ + (builtins.map (hook: + lib.nameValuePair hook.id { before = hook.before; after = hook.after; } + )) + lib.listToAttrs + (lib.generators.toPretty opts) + ]; + in + throw '' + The hooks can't be sorted because of a cycle in the dependency graph: + + ${concatStringsSep " -> " (getIds sortedHooks.cycle)} + + which leads to a loop back to: ${concatStringsSep ", " (getIds sortedHooks.loops)} + + Try removing the conflicting hook ids from the `before` and `after` attributes of these hooks: + + ${prettyPrintCycle { indent = " "; } sortedHooks.cycle} + ''; configFile = performAssertions (