kommode/gitea: only keep 3 backups

This commit is contained in:
h7x4 2025-09-03 22:46:06 +02:00
parent 736dc44008
commit 54434b7f93
No known key found for this signature in database
GPG Key ID: 9F2F7D8250F35146

View File

@ -1,4 +1,4 @@
{ config, values, lib, unstablePkgs, ... }:
{ config, values, lib, pkgs, unstablePkgs, ... }:
let
cfg = config.services.gitea;
domain = "git.pvv.ntnu.no";
@ -184,4 +184,14 @@ in {
};
networking.firewall.allowedTCPPorts = [ sshPort ];
# Only keep n backup files at a time
systemd.services.gitea-dump.postStop = let
cu = prog: "'${lib.getExe' pkgs.coreutils prog}'";
backupCount = 3;
in ''
for file in $(${cu "ls"} -t1 '${cfg.dump.backupDir}' | ${cu "sort"} --reverse | ${cu "tail"} -n+${toString (backupCount - 1)}); do
${cu "rm"} "$file"
done
'';
}