2023-03-18 06:19:10 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2022-04-12 03:00:04 +00:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
services.postgresql = {
|
|
|
|
|
enable = true;
|
|
|
|
|
checkConfig = true;
|
2023-09-07 23:47:24 +00:00
|
|
|
ensureDatabases = [
|
|
|
|
|
"dendrite"
|
|
|
|
|
"nextcloud"
|
|
|
|
|
];
|
2023-03-18 04:59:49 +00:00
|
|
|
#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";
|
2023-12-11 21:52:47 +00:00
|
|
|
ensureDBOwnership = true;
|
2023-03-18 04:59:49 +00:00
|
|
|
} {
|
|
|
|
|
name = "dendrite";
|
2023-12-11 21:52:47 +00:00
|
|
|
ensureDBOwnership = true;
|
2022-04-12 03:00:04 +00:00
|
|
|
} ];
|
|
|
|
|
settings = {
|
|
|
|
|
log_connections = true;
|
|
|
|
|
log_statement = "all";
|
|
|
|
|
logging_collector = true;
|
2023-03-07 22:55:02 +00:00
|
|
|
log_filename = "postgresql.log";
|
2022-04-12 03:00:04 +00:00
|
|
|
};
|
|
|
|
|
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 = [
|
2023-03-18 04:59:49 +00:00
|
|
|
"dendrite"
|
2023-09-07 23:47:24 +00:00
|
|
|
"nextcloud"
|
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";
|
2023-05-29 02:42:37 +00:00
|
|
|
compress = true;
|
|
|
|
|
compresscmd = "${pkgs.xz}/bin/xz";
|
2022-08-24 03:08:15 +00:00
|
|
|
};
|
2022-04-12 03:00:04 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-07 07:22:45 +00:00
|
|
|
greg.backup.jobs.greg-postgresql-backup = {
|
2022-08-24 03:08:15 +00:00
|
|
|
src = "/var/backup/postgresql";
|
|
|
|
|
dest = "linode-postgres";
|
|
|
|
|
user = "postgres";
|
2022-04-12 03:00:04 +00:00
|
|
|
};
|
|
|
|
|
}
|