dotfiles/modules/nixos/services/postgresql/default.nix
2025-10-13 23:27:40 -05:00

72 lines
1.4 KiB
Nix
Executable file

{ flake, lib, ... }:
let
inherit (flake.config.machines.devices)
ceres
;
inherit (flake.config.services)
instances
;
service = instances.postgresql;
backupPath = "${instances.syncthing.paths.path1}/${service.name}";
in
{
services = {
postgresqlBackup = {
enable = true;
location = backupPath;
# compression = "zstd";
startAt = "*-*-* 22:00:00";
# backupAll = true;
databases = [
instances.mastodon.name
instances.firefly-iii.name
];
};
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 = [
instances.nextcloud.name
instances.mastodon.name
instances.forgejo.name
instances.syncthing.name
];
systemd.services = {
postgresqlBackup-firefly-iii = {
serviceConfig = {
Group = lib.mkForce instances.syncthing.name;
};
};
postgresqlBackup-mastodon = {
serviceConfig = {
Group = lib.mkForce instances.syncthing.name;
};
};
};
system.activationScripts.postgresCommands = ''
chown -R ${service.name}:${service.name} ${service.paths.path0}
'';
}