Files
nixos/hosts/linode/postgres.nix
T

70 lines
1.7 KiB
Nix
Raw Normal View History

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-03-18 04:59:49 +00:00
ensureDatabases = [ "nextcloud" "gitea" "dendrite" ];
#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";
2022-09-23 01:29:05 +00:00
} {
name = "gitea";
ensurePermissions."DATABASE gitea" = "ALL PRIVILEGES";
2023-03-18 04:59:49 +00:00
} {
name = "dendrite";
ensurePermissions."DATABASE dendrite" = "ALL PRIVILEGES";
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 = [
2022-09-23 01:29:05 +00:00
"gitea"
2022-06-13 16:15:02 +00:00
"nextcloud"
2023-03-18 04:59:49 +00:00
"dendrite"
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-03-18 06:19:10 +00:00
extraConfig = (lib.strings.concatStringsSep "\n" [
"compress"
"compresscmd=${pkgs.xz}/bin/xz"
]);
2022-08-24 03:08:15 +00:00
};
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
};
}