Set up PostgreSQL

This commit is contained in:
Natsu Kagami 2021-10-31 16:33:27 -04:00
parent 0d59455d36
commit 6efb74062b
Signed by: nki
GPG key ID: 7306B3D3C3AD6E51
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,42 @@
{ pkgs, config, lib, ... } :
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.
userFromDatabase = databaseName : {
name = databaseName;
ensurePermissions = {
"DATABASE ${databaseName}" = "ALL PRIVILEGES";
};
};
in
{
options.cloud.postgresql.databases = mkOption {
type = types.listOf types.str;
default = [];
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;
ensureUsers = map userFromDatabase cfg.databases;
};
# Backup settings
config.services.postgresqlBackup = {
enable = true;
};
}

View file

@ -3,6 +3,8 @@
./hardware-configuration.nix
./networking.nix # generated at runtime by nixos-infect
# Set up postgresql
../modules/postgresql
];
boot.cleanTmpDir = true;