{ pkgs, config, ... }: let secrets = config.services.secrets.secrets; mailConfig = config.services.mailserver; backupPrepareCommand = "${ (pkgs.writeShellScriptBin "backupPrepareCommand" '' systemctl start postgresqlBackup-roundcube --wait '') }/bin/backupPrepareCommand"; in { environment.systemPackages = with pkgs; [ restic (pkgs.writeShellScriptBin "restic-mail" '' env \ RESTIC_PASSWORD_FILE=${secrets.restic_password.path} \ $(cat ${secrets.restic_env.path}) \ ${pkgs.restic}/bin/restic $@ '') ]; services.restic.backups.mail = { user = "root"; paths = [ "/var/backup/postgresql" mailConfig.vmail.directory mailConfig.sieveDirectory mailConfig.dkim.directory "/var/lib/redis-rspamd" ]; # repository is overrided in environmentFile to contain auth # make sure to keep up to date when changing repository repository = "rest:https://storage-restic.owo.monster/Mail"; passwordFile = "${secrets.restic_password.path}"; environmentFile = "${secrets.restic_env.path}"; pruneOpts = [ "--keep-last 100" ]; timerConfig = { OnBootSec = "1m"; OnCalendar = "8h"; }; inherit backupPrepareCommand; }; services.postgresql.enable = true; services.postgresqlBackup = { enable = true; backupAll = false; databases = ["roundcube"]; compression = "zstd"; }; }