Files
nixos/hosts/linode/postgres.nix
T

58 lines
1.3 KiB
Nix
Raw Normal View History

2022-04-12 15:11:56 +00:00
{ config, pkgs, ... }:
2022-04-12 03:00:04 +00:00
{
services.postgresql = {
enable = true;
checkConfig = true;
2022-04-12 15:11:56 +00:00
ensureDatabases = [ "nextcloud" ];
initialScript = pkgs.writeText "create-matrix-db.sql" ''
CREATE ROLE "matrix-synapse" WITH LOGIN;
CREATE DATABASE "synapse" WITH OWNER "matrix-synapse" TEMPLATE template0 LC_COLLATE = "C" LC_CTYPE = "C";
GRANT ALL PRIVILEGES ON DATABASE "synapse" TO "matrix-synapse";
''; # These are done manually in order to set the LC_COLLATE values properly
2022-04-12 03:00:04 +00:00
ensureUsers = [ {
2022-04-12 15:11:56 +00:00
name = "nextcloud";
ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
2022-04-12 03:00:04 +00:00
} {
name = "root";
ensurePermissions."ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES";
} ];
settings = {
log_connections = true;
log_statement = "all";
logging_collector = true;
};
identMap = ''
2022-04-12 15:11:56 +00:00
root root postgres
2022-04-12 03:00:04 +00:00
'';
};
2022-06-13 16:15:02 +00:00
services.postgresqlBackup = {
enable = true;
databases = [
"nextcloud"
2022-08-24 04:39:55 +00:00
"synapse"
2022-06-13 16:15:02 +00:00
];
};
2022-04-12 03:00:04 +00:00
services.logrotate = {
enable = true;
2022-06-10 05:48:18 +00:00
settings = {
2022-08-24 03:08:15 +00:00
postgresBackup = {
2022-04-12 03:00:04 +00:00
enable = true;
2022-06-10 05:48:18 +00:00
files = "${config.services.postgresqlBackup.location}/*.gz";
2022-04-12 03:00:04 +00:00
};
2022-08-24 03:08:15 +00:00
postgresLog = {
enable = true;
files = "/var/lib/postgresql/*/log/*.log";
};
2022-04-12 03:00:04 +00:00
};
};
2022-08-24 03:08:15 +00:00
greg.backup.jobs.postgresql = {
src = "/var/backup/postgresql";
dest = "linode-postgres";
user = "postgres";
2022-04-12 03:00:04 +00:00
};
}