dotfiles/modules/nixos/services/postgresql/postgresCeres/default.nix

85 lines
1.8 KiB
Nix
Raw Normal View History

2025-10-14 00:16:31 -05:00
{
flake,
lib,
pkgs,
...
}:
2025-10-01 19:51:55 -05:00
let
inherit (flake.config.machines.devices) ceres;
inherit (flake.config.services) instances;
2025-10-01 19:51:55 -05:00
2025-10-09 22:58:38 -05:00
service = instances.postgresql;
2025-10-14 00:16:31 -05:00
# backupPath = "${instances.syncthing.paths.path1}/${service.name}";
2025-10-01 19:51:55 -05:00
in
{
services = {
postgresqlBackup = {
enable = true;
2025-10-14 00:16:31 -05:00
# location = backupPath;
# compression = "zstd";
2025-10-14 00:16:31 -05:00
startAt = "*-*-* 07:00:00";
databases = [
instances.mastodon.name
instances.firefly-iii.name
];
2025-10-01 19:51:55 -05:00
};
postgresql = {
enable = true;
};
};
networking = {
firewall = {
allowedTCPPorts = [
service.ports.port0
];
};
};
fileSystems."/var/lib/postgresql" = {
device = service.paths.path0;
fsType = "none";
options = [
"bind"
];
depends = [
ceres.storage0.mount
];
};
users.users.${service.name}.extraGroups = [
2025-10-09 22:58:38 -05:00
instances.mastodon.name
instances.forgejo.name
2025-10-10 02:03:44 -05:00
instances.syncthing.name
2025-10-01 19:51:55 -05:00
];
2025-10-14 00:16:31 -05:00
systemd.services.sync-postgres-backups = {
description = "Sync PostgreSQL backups to Syncthing";
after = [
"postgresqlBackup-firefly-iii.service"
"postgresqlBackup-mastodon.service"
];
serviceConfig = {
Type = "oneshot";
User = instances.syncthing.name;
Group = instances.syncthing.name;
2025-10-13 23:27:40 -05:00
};
2025-10-14 00:16:31 -05:00
script = ''
${pkgs.rsync}/bin/rsync -av --delete \
/var/backup/postgresql/ \
${instances.syncthing.paths.path1}/${service.name}/
${pkgs.rsync}/bin/rsync -av --delete \
/var/lib/${instances.firefly-iii.name}/storage/ \
${instances.syncthing.paths.path1}/${service.name}/firefly-iii-storage/
'';
2025-10-13 23:27:40 -05:00
};
2025-10-14 00:16:31 -05:00
systemd.timers.sync-postgres-backups = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* 22:10:00"; # 10 mins after backup
Persistent = true;
};
};
2025-10-01 19:51:55 -05:00
}