nixfiles/hosts/hetzner-arm/profiles/restic.nix

102 lines
2.9 KiB
Nix
Raw Normal View History

2024-07-20 12:24:27 +01:00
{
self,
pkgs,
2024-07-20 12:46:35 +01:00
lib,
2024-07-20 12:24:27 +01:00
config,
...
}: let
2024-07-20 12:46:35 +01:00
inherit (lib.lists) forEach;
2024-07-20 12:48:21 +01:00
inherit (lib.strings) concatStringsSep;
2024-07-20 12:46:35 +01:00
2024-07-20 12:58:45 +01:00
inherit (builtins) attrNames;
2024-07-20 12:24:27 +01:00
inherit (config.services.secrets) secrets;
backupSchedules = import "${self}/data/backupSchedules.nix";
repoRoot = "s3:s3.eu-central-003.backblazeb2.com/Chaos-Backups/Restic";
in {
2024-07-20 12:46:35 +01:00
environment.systemPackages = [
# TODO: add ones in container too
2024-07-20 12:49:09 +01:00
(pkgs.writeShellScriptBin "restic-all" ''
2024-07-20 12:58:45 +01:00
${concatStringsSep "\n" (forEach (attrNames config.services.restic.backups) (
name: "restic-${name} $@"
))}
2024-07-20 12:49:09 +01:00
'')
2024-07-20 12:46:35 +01:00
];
2024-07-20 12:24:27 +01:00
services.restic.backups = {
social = {
user = "root";
paths = [
"/var/lib/gotosocial"
];
repository = "${repoRoot}/Social-02";
2024-07-20 12:30:18 +01:00
environmentFile = secrets.restic_backups_env.path;
passwordFile = secrets.restic_password_social.path;
2024-07-20 12:24:27 +01:00
createWrapper = true;
pruneOpts = ["--keep-last 10"];
timerConfig = backupSchedules.restic.medium;
backupPrepareCommand = let
# 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
gotoSocialConfigFile = (pkgs.formats.yaml {}).generate "config.yml" config.services.gotosocial.settings;
gotoSocialAdmin = "${(pkgs.writeShellScriptBin "gts-admin" ''
exec systemd-run \
-u gotosocial-admin.service \
-p Group=gotosocial \
-p User=gotosocial \
-q -t -G --wait --service-type=exec \
${pkgs.gotosocial}/bin/gotosocial --config-path ${gotoSocialConfigFile} admin "$@"
'')}/bin/gts-admin";
in "${
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
systemctl stop gotosocial
${gotoSocialAdmin} export --path /var/lib/gotosocial/gts-export.json
${gotoSocialAdmin} media prune all --dry-run=false
systemctl start gotosocial
'')
}/bin/backupPrepareCommand";
backupCleanupCommand = "${
(pkgs.writeShellScriptBin "backupCleanupCommand" ''
rm /var/lib/gotosocial/gts-export.json || true
'')
}/bin/backupCleanupCommand";
};
2024-07-20 12:58:45 +01:00
forgejo = {
user = "root";
paths = [
"/var/lib/forgejo"
];
repository = "${repoRoot}/Forgejo";
environmentFile = secrets.restic_backups_env.path;
passwordFile = secrets.restic_password_forgejo.path;
createWrapper = true;
2024-07-20 13:23:50 +01:00
pruneOpts = ["--keep-last 50"];
timerConfig = backupSchedules.restic.high;
};
radicale = {
user = "root";
paths = [
"/var/lib/radicale"
];
repository = "${repoRoot}/Radicale";
environmentFile = secrets.restic_backups_env.path;
passwordFile = secrets.restic_password_radicale.path;
createWrapper = true;
2024-07-20 12:58:45 +01:00
pruneOpts = ["--keep-last 50"];
timerConfig = backupSchedules.restic.high;
};
2024-07-20 12:24:27 +01:00
};
}