From 3a73eae98d714c40b7ff0f1d837f56b28173f3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Bon=C3=A9?= Date: Tue, 3 Mar 2026 18:43:40 +0100 Subject: [PATCH 1/3] Enable rotating gitea backups --- m/tent/gitea.nix | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/m/tent/gitea.nix b/m/tent/gitea.nix index 5c458306..53c3b850 100644 --- a/m/tent/gitea.nix +++ b/m/tent/gitea.nix @@ -26,6 +26,44 @@ SENDMAIL_ARGS = "--"; }; }; + + dump = { + enable = false; # Do not enable NixOS module, use our custom systemd script below + backupDir = "/vault/gitea"; + }; + }; + + systemd.services.gitea-dump-rotating = let + cfg = config.services.gitea; + exe = lib.getExe cfg.package; + in { + description = "gitea dump rotation"; + after = [ "gitea.service" ]; + path = [ cfg.package ]; + + environment = { + USER = cfg.user; + HOME = cfg.stateDir; + GITEA_WORK_DIR = cfg.stateDir; + GITEA_CUSTOM = cfg.customDir; + }; + + serviceConfig = { + Type = "oneshot"; + User = cfg.user; + WorkingDirectory = cfg.dump.backupDir; + }; + + script = '' + ${exe} dump --type ${cfg.dump.type} --file "gitea-dump-$(date +%a).${cfg.dump.type}" + ''; + }; + + systemd.timers.gitea-dump-rotating = { + description = "Update timer for gitea-dump-rotating"; + partOf = [ "gitea-dump-rotating.service" ]; + wantedBy = [ "timers.target" ]; + timerConfig.OnCalendar = config.services.gitea.dump.interval; }; # Allow gitea user to send mail From 11684d2dc9c0f099ac402103972c717a3132426b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Bon=C3=A9?= Date: Thu, 5 Mar 2026 11:12:26 +0100 Subject: [PATCH 2/3] Override files in rotating gitea dump service --- m/tent/gitea.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/m/tent/gitea.nix b/m/tent/gitea.nix index 53c3b850..2c5b11f1 100644 --- a/m/tent/gitea.nix +++ b/m/tent/gitea.nix @@ -54,8 +54,9 @@ WorkingDirectory = cfg.dump.backupDir; }; + # gitea dump does not allow overriding files. Instead dump to stdout with - script = '' - ${exe} dump --type ${cfg.dump.type} --file "gitea-dump-$(date +%a).${cfg.dump.type}" + ${exe} dump --type ${cfg.dump.type} --file - >"gitea-dump-$(date +%a).${cfg.dump.type}" ''; }; From b34a26a37314bb7839d53170136736c08db9c6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Bon=C3=A9?= Date: Thu, 5 Mar 2026 11:27:45 +0100 Subject: [PATCH 3/3] More robust gitea dump override --- m/tent/gitea.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/m/tent/gitea.nix b/m/tent/gitea.nix index 2c5b11f1..dfbe1229 100644 --- a/m/tent/gitea.nix +++ b/m/tent/gitea.nix @@ -54,9 +54,10 @@ WorkingDirectory = cfg.dump.backupDir; }; - # gitea dump does not allow overriding files. Instead dump to stdout with - script = '' - ${exe} dump --type ${cfg.dump.type} --file - >"gitea-dump-$(date +%a).${cfg.dump.type}" + name="gitea-dump-$(date +%a).${cfg.dump.type}" + ${exe} dump --type ${cfg.dump.type} --file - >"$name.tmp" + mv "$name.tmp" "$name" ''; };