1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 18:59:47 +01:00

git: add module for git maintenance (#5772)

Adds module for git-scm.com/docs/git-maintenance.
This commit is contained in:
Perchun Pak 2024-10-11 14:48:52 +02:00 committed by GitHub
parent 5828309542
commit 65ae9c1473
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -214,6 +214,41 @@ in {
};
};
maintenance = {
enable = mkEnableOption "" // {
description = ''
Enable the automatic {command}`git maintenance`.
See <https://git-scm.com/docs/git-maintenance>.
'';
};
repositories = mkOption {
type = with types; listOf str;
default = [ ];
description = ''
Repositories on which {command}`git maintenance` should run.
Should be a list of absolute paths.
'';
};
timers = mkOption {
type = types.attrsOf types.str;
default = {
hourly = "*-*-* 1..23:53:00";
daily = "Tue..Sun *-*-* 0:53:00";
weekly = "Mon 0:53:00";
};
description = ''
Systemd timers to create for scheduled {command}`git maintenance`.
Key is passed to `--schedule` argument in {command}`git maintenance run`
and value is passed to `Timer.OnCalendar` in `systemd.user.timers`.
'';
};
};
diff-highlight = {
enable = mkEnableOption "" // {
description = ''
@ -501,6 +536,48 @@ in {
};
})
(mkIf cfg.maintenance.enable {
programs.git.iniContent.maintenance.repo = cfg.maintenance.repositories;
systemd.user.services."git-maintenance@" = {
Unit = {
Description = "Optimize Git repositories data";
Documentation = [ "man:git-maintenance(1)" ];
};
Service = {
Type = "oneshot";
ExecStart = let exe = lib.getExe cfg.package;
in ''
"${exe}" --exec-path="${exe}" for-each-repo --config=maintenance.repo maintenance run --schedule=%i
'';
LockPersonality = "yes";
MemoryDenyWriteExecute = "yes";
NoNewPrivileges = "yes";
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_VSOCK";
RestrictNamespaces = "yes";
RestrictRealtime = "yes";
RestrictSUIDSGID = "yes";
SystemCallArchitectures = "native";
SystemCallFilter = "@system-service";
};
};
systemd.user.timers = let
toSystemdTimer = name: time:
lib.attrsets.nameValuePair "git-maintenance@${name}" {
Unit.Description = "Optimize Git repositories data";
Timer = {
OnCalendar = time;
Persistent = true;
};
Install.WantedBy = [ "timers.target" ];
};
in lib.attrsets.mapAttrs' toSystemdTimer cfg.maintenance.timers;
})
(mkIf cfg.diff-highlight.enable {
programs.git.iniContent = let
dhCommand =