Skip to content

Commit

Permalink
Merge branch 'master' into cabal2nix
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrohitsingh682 committed Dec 21, 2024
2 parents 3e3ebb2 + 0ddd26d commit a971492
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
35 changes: 31 additions & 4 deletions modules/hook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,39 @@ in
'';
};

id = mkOption {
type = types.str;
default = name;
defaultText = "the attribute name the hook submodule is bound to";
description =
''
The unique identifier for the hook.
You do not need to set or modify this value.
The `id` is used to reference a hook when using `pre-commit run <id>`.
It can also be used to reference the hook in other hooks' `before` and `after` fields to define the order in which hooks run.
The `id` is set to the attribute name the hook submodule is bound to in the parent module.
For example, the `id` of following hook would be `my-hook`.
```nix
{
hooks = {
my-hook = {
enable = true;
entry = "my-hook";
};
}
}
```
'';
};

name = mkOption {
type = types.str;
defaultText = lib.literalMD "internal name, same as `id`";
default = name;
defaultText = lib.literalMD "the attribute name the hook submodule is bound to, same as `id`";
description =
''
The name of the hook. Shown during hook execution.
Expand Down Expand Up @@ -202,14 +231,12 @@ in
'';
default = [ ];
};

};

config = {
raw =
{
inherit (config) name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args before after;
id = config.name;
inherit (config) id name entry language files types types_or exclude_types pass_filenames fail_fast require_serial stages verbose always_run args;
exclude = mergeExcludes config.excludes;
};
};
Expand Down
2 changes: 1 addition & 1 deletion modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ in
binPath = migrateBinPathToPackage hooks.biome "/bin/biome";
cmdArgs =
mkCmdArgs [
[ (hooks.biome.settings.write) "--apply" ]
[ (hooks.biome.settings.write) "--write" ]
[ (hooks.biome.settings.configPath != "") "--config-path ${hooks.biome.settings.configPath}" ]
];
in
Expand Down
46 changes: 27 additions & 19 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let
mapAttrsToList
mkOption
types
removeAttrs
remove
;

Expand All @@ -34,25 +33,34 @@ let
let
sortedHooks = lib.toposort
(a: b: builtins.elem b.id a.before || builtins.elem a.id b.after)
(mapAttrsToList
(id: value:
value.raw // {
inherit id;
before = value.raw.before;
after = value.raw.after;
}
)
enabledHooks
);
cleanedHooks = builtins.map (
hook:
removeAttrs hook [
"before"
"after"
]
) sortedHooks.result;
(builtins.attrValues enabledHooks);
in
cleanedHooks;
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 (
Expand Down

0 comments on commit a971492

Please sign in to comment.