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

62 lines
1.2 KiB
Nix
Raw Normal View History

2025-10-01 19:51:55 -05:00
{ flake, ... }:
let
inherit (flake.config.machines.devices)
ceres
;
2025-10-09 22:58:38 -05:00
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-10 02:03:44 -05:00
backupPath = "${instances.syncthing.paths.path1}/${service.name}";
2025-10-01 19:51:55 -05:00
in
{
services = {
postgresqlBackup = {
enable = true;
2025-10-10 00:14:36 -05:00
location = backupPath;
2025-10-09 23:20:51 -05:00
compression = "zstd";
startAt = "*-*-* 07:00:00";
2025-10-01 19:51:55 -05:00
databases = [
2025-10-09 22:58:38 -05:00
instances.mastodon.name
instances.forgejo.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.nextcloud.name
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
];
system.activationScripts.postgresCommands = ''
2025-10-10 02:08:29 -05:00
if [ ! -d "${service.paths.path0}/15" ]; then
chown -R ${service.name}:${service.name} ${service.paths.path0}
fi
2025-10-01 19:51:55 -05:00
'';
}