Files
nixos/modules/nixos/db.nix
T

78 lines
1.6 KiB
Nix
Raw Normal View History

2024-10-19 01:19:59 -05:00
{
config,
lib,
pkgs,
...
}:
2024-02-27 14:40:35 -06:00
let
cfg = config.greg.databases;
dbs = (lib.attrNames cfg);
in
{
options.greg.databases = lib.mkOption {
default = { };
2024-10-19 01:19:59 -05:00
type =
with lib.types;
attrsOf (
submodule (
{ ... }:
{
# Options reserved for future expansion
options = { };
}
)
);
};
2024-02-27 14:40:35 -06:00
config = lib.mkIf (dbs != [ ]) {
services = {
postgresql = {
enable = true;
package = pkgs.postgresql_15;
checkConfig = true;
ensureDatabases = dbs;
2024-10-19 01:19:59 -05:00
ensureUsers = map (db: {
name = db;
ensureDBOwnership = true;
}) dbs;
settings = {
log_connections = true;
log_statement = "all";
logging_collector = true;
log_filename = "postgresql.log";
};
identMap = "root root postgres";
};
2024-02-27 14:40:35 -06:00
postgresqlBackup = {
enable = true;
databases = dbs;
};
2024-02-27 14:40:35 -06:00
logrotate = {
enable = true;
settings = {
postgresqlBackup = {
enable = true;
files = "${config.services.postgresqlBackup.location}/*.gz";
};
postgresLog = {
enable = true;
files = "/var/lib/postgresql/*/log/*.log";
compress = true;
compresscmd = "${pkgs.xz}/bin/xz";
};
};
};
2024-02-27 14:40:35 -06:00
};
2024-02-27 14:40:35 -06:00
greg.backup.jobs.greg-postgresql-backup = {
src = config.services.postgresqlBackup.location;
dest = "database-${config.networking.hostName}";
id = "${config.networking.hostName}-postgres-backup";
};
};
2024-02-27 14:40:35 -06:00
}