dotfiles/nixos/modules/services/postgresql.nix

40 lines
955 B
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{flake, ...}: let
inherit (flake.config.system.device) server;
2024-10-19 18:22:29 -05:00
inherit (flake.config.service.instance) postgresql;
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
'';
}