-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lefthook: run directly instead of (default) complex script
this helps with running hooks outside the devshell, for example: - Jetbrains IDE's Commit dialog for completeness' sake also updated all dependencies switching to direct paths instead of command invocations
- Loading branch information
Showing
3 changed files
with
37 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
let | ||
inherit (inputs) nixpkgs; | ||
l = nixpkgs.lib // builtins; | ||
in { | ||
data = {}; | ||
format = "yaml"; | ||
output = "lefthook.yml"; | ||
packages = [nixpkgs.lefthook]; | ||
hook.extra = d: let | ||
# Add an extra hook for adding required stages whenever the file changes | ||
skip_attrs = [ | ||
lib = nixpkgs.lib // builtins; | ||
|
||
mkScript = stage: | ||
nixpkgs.writeScript "lefthook-${stage}" '' | ||
#!${nixpkgs.runtimeShell} | ||
[ "$LEFTHOOK" == "0" ] || ${lib.getExe nixpkgs.lefthook} run "${stage}" "$@" | ||
''; | ||
|
||
toStagesConfig = config: | ||
lib.removeAttrs config [ | ||
"colors" | ||
"extends" | ||
"skip_output" | ||
"source_dir" | ||
"source_dir_local" | ||
]; | ||
stages = l.attrNames (l.removeAttrs d skip_attrs); | ||
stagesStr = l.concatStringsSep " " stages; | ||
in '' | ||
# Install configured hooks | ||
for stage in ${stagesStr}; do | ||
${l.getExe nixpkgs.lefthook} add -f "$stage" | ||
done | ||
''; | ||
in { | ||
data = {}; | ||
format = "yaml"; | ||
output = "lefthook.yml"; | ||
packages = [nixpkgs.lefthook]; | ||
# Add an extra hook for adding required stages whenever the file changes | ||
hook.extra = config: | ||
lib.pipe config [ | ||
toStagesConfig | ||
lib.attrNames | ||
(lib.map (stage: ''ln -sf "${mkScript stage}" ".git/hooks/${stage}"'')) | ||
(stages: | ||
lib.optional (stages != []) "mkdir -p .git/hooks" | ||
++ stages) | ||
(lib.concatStringsSep "\n") | ||
]; | ||
} |