dotfiles/nixos/modules/services/postgresql.nix

40 lines
960 B
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{flake, ...}: let
2024-11-04 20:49:43 -06:00
inherit (flake.config.machines.devices) server;
inherit (flake.config.services.instances) postgresql;
2024-10-19 18:22:29 -05:00
service = postgresql;
2024-10-06 15:25:05 -05:00
in {
services = {
postgresqlBackup = {
enable = true;
2024-10-19 18:22:29 -05:00
location = service.paths.path0;
2024-10-19 16:00:30 -05:00
databases = ["mastodon" "nextcloud" "peertube" "forgejo" "wiki"];
2024-10-06 15:25:05 -05:00
};
postgresql = {
enable = true;
};
};
networking = {
firewall = {
allowedTCPPorts = [
2024-10-19 18:22:29 -05:00
service.ports.port0
2024-10-06 15:25:05 -05:00
];
};
};
fileSystems."/var/lib/postgresql" = {
2024-10-19 18:22:29 -05:00
device = service.paths.path0;
2024-10-06 15:25:05 -05:00
fsType = "none";
options = ["bind"];
depends = [server.storage0.mount];
};
2024-10-19 18:22:29 -05:00
systemd.tmpfiles.rules = ["Z ${service.paths.path0} 700 ${service.name} ${service.name} -"];
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
users.users.${service.name}.extraGroups = ["nextcloud" "mastodon" "forgejo"];
2024-10-06 15:25:05 -05:00
system.activationScripts.postgresCommands = ''
2024-10-19 18:22:29 -05:00
chown -R ${service.name}:${service.name} ${service.paths.path0}
2024-10-06 15:25:05 -05:00
'';
}