nix-home/modules/cloud/postgresql/default.nix

46 lines
1 KiB
Nix
Raw Normal View History

2022-05-31 16:45:33 +00:00
{ pkgs, config, lib, ... }:
2021-10-31 20:33:27 +00:00
with lib;
let
cfg = config.cloud.postgresql;
# From a database name, create an "ensureUser"
# entry with the same name and assign all permissions
# to that database.
2022-05-31 16:45:33 +00:00
userFromDatabase = databaseName: {
2021-10-31 20:33:27 +00:00
name = databaseName;
ensurePermissions = {
"DATABASE ${databaseName}" = "ALL PRIVILEGES";
};
};
in
{
options.cloud.postgresql.databases = mkOption {
type = types.listOf types.str;
2022-05-31 16:45:33 +00:00
default = [ ];
2021-10-31 20:33:27 +00:00
description = ''
The list of databases to be created.
An user with the same name
and full access to the database will be created.
'';
};
# PostgreSQL settings.
config.services.postgresql = {
enable = true;
package = pkgs.postgresql_13;
ensureDatabases = cfg.databases;
2023-05-04 21:06:26 +00:00
ensureUsers = (map userFromDatabase cfg.databases) ++ [{
name = "root";
ensurePermissions = { "ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES"; };
}];
2021-10-31 20:33:27 +00:00
};
# Backup settings
config.services.postgresqlBackup = {
enable = true;
};
}