2023-07-29 16:41:20 +01:00
|
|
|
{
|
2024-03-09 22:18:26 +00:00
|
|
|
self,
|
2023-07-29 16:41:20 +01:00
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2024-03-10 17:26:18 +00:00
|
|
|
inherit (config.services.secrets) secrets;
|
2024-03-09 22:18:26 +00:00
|
|
|
backupSchedules = import "${self}/data/backupSchedules.nix";
|
2023-07-29 16:41:20 +01:00
|
|
|
|
|
|
|
# Because gotosocial-admin isn't a seporate package we need to generate a seperate config
|
|
|
|
# and duplicate the wrapper for use in a systemd unit
|
2024-01-25 13:41:33 +00:00
|
|
|
gotoSocialConfigFile = (pkgs.formats.yaml {}).generate "config.yml" config.services.gotosocial.settings;
|
|
|
|
gotoSocialAdmin = "${(pkgs.writeShellScriptBin "gts-admin" ''
|
2023-07-29 16:41:20 +01:00
|
|
|
exec systemd-run \
|
|
|
|
-u gotosocial-admin.service \
|
|
|
|
-p Group=gotosocial \
|
|
|
|
-p User=gotosocial \
|
|
|
|
-q -t -G --wait --service-type=exec \
|
2024-01-25 13:41:33 +00:00
|
|
|
${pkgs.gotosocial}/bin/gotosocial --config-path ${gotoSocialConfigFile} admin "$@"
|
|
|
|
'')}/bin/gts-admin";
|
2023-07-29 16:41:20 +01:00
|
|
|
|
|
|
|
backupPrepareCommand = "${
|
|
|
|
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
|
2023-09-04 18:09:16 +01:00
|
|
|
systemctl stop gotosocial
|
|
|
|
|
2024-01-25 13:41:33 +00:00
|
|
|
${gotoSocialAdmin} export --path /var/lib/gotosocial/gts-export.json
|
2023-09-04 18:09:16 +01:00
|
|
|
|
2024-01-25 13:41:33 +00:00
|
|
|
${gotoSocialAdmin} media prune all --dry-run=false
|
2023-09-04 18:09:16 +01:00
|
|
|
|
|
|
|
systemctl start gotosocial
|
2023-07-29 16:41:20 +01:00
|
|
|
'')
|
|
|
|
}/bin/backupPrepareCommand";
|
|
|
|
|
|
|
|
backupCleanupCommand = "${(pkgs.writeShellScriptBin "backupCleanupCommand" ''
|
2023-09-08 21:29:08 +01:00
|
|
|
rm /var/lib/gotosocial/gts-export.json || true
|
2023-07-29 16:41:20 +01:00
|
|
|
'')}/bin/backupCleanupCommand";
|
|
|
|
in {
|
|
|
|
services.restic.backups.social = {
|
|
|
|
user = "root";
|
|
|
|
paths = [
|
|
|
|
"/var/lib/gotosocial"
|
|
|
|
];
|
|
|
|
|
2024-07-06 17:20:28 +01:00
|
|
|
repository = "s3:s3.eu-central-003.backblazeb2.com/Chaos-Backups/Restic/Social";
|
2023-09-21 05:06:27 +01:00
|
|
|
passwordFile = "${secrets.restic_password.path}";
|
|
|
|
environmentFile = "${secrets.restic_env.path}";
|
2024-07-06 17:20:28 +01:00
|
|
|
createWrapper = true;
|
2023-07-29 16:41:20 +01:00
|
|
|
|
2024-03-09 22:18:26 +00:00
|
|
|
pruneOpts = ["--keep-last 10"];
|
|
|
|
# Don't want to cause too much downtime and take too long to prune media
|
|
|
|
timerConfig = backupSchedules.restic.medium;
|
2023-07-29 16:41:20 +01:00
|
|
|
|
|
|
|
inherit backupPrepareCommand;
|
|
|
|
inherit backupCleanupCommand;
|
|
|
|
};
|
|
|
|
}
|