git: add config helper for hooks

This commit is contained in:
Charlie Moog 2022-09-04 11:57:45 -05:00 committed by Robert Helgesson
parent 2e41a1bab3
commit 340ec22f6f
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 53 additions and 0 deletions

View file

@ -201,6 +201,21 @@ in {
'';
};
hooks = mkOption {
type = types.attrsOf types.path;
default = { };
example = literalExpression ''
{
pre-commit = ./pre-commit-script;
}
'';
description = ''
Configuration helper for Git hooks.
See <link xlink:href="https://git-scm.com/docs/githooks" />
for reference.
'';
};
iniContent = mkOption {
type = gitIniType;
internal = true;
@ -449,6 +464,15 @@ in {
};
})
(mkIf (cfg.hooks != { }) {
programs.git.iniContent = {
core.hooksPath = let
entries =
mapAttrsToList (name: path: { inherit name path; }) cfg.hooks;
in toString (pkgs.linkFarm "git-hooks" entries);
};
})
(mkIf (cfg.aliases != { }) { programs.git.iniContent.alias = cfg.aliases; })
(mkIf (lib.isAttrs cfg.extraConfig) {