nixos-hypervisor/services/postgresql/default.nix

50 lines
1.4 KiB
Nix
Raw Permalink Normal View History

2024-09-09 15:19:57 +02:00
{ lib, config, pkgs, ... }:
let
cfg = config.services.vm_postgresql;
in
{
options.services.vm_postgresql = {
enable = lib.mkEnableOption "Enable minimal config";
};
config = lib.mkIf cfg.enable {
services.postgresql = {
enable = true;
2024-11-28 10:52:27 +01:00
package = pkgs.postgresql_16;
2024-09-09 15:19:57 +02:00
enableTCPIP = true;
settings.port = 5432;
2024-10-24 14:26:28 +02:00
ensureDatabases = [
"gitea"
"nextcloud"
"netbox"
"authentik"
"grafana"
];
2024-09-09 15:19:57 +02:00
ensureUsers = [
{
name = "gitea";
ensureDBOwnership = true;
}
{
name = "nextcloud";
ensureDBOwnership = true;
}
];
2024-10-24 14:26:28 +02:00
authentication = "
host nextcloud nextcloud 192.168.1.44/32 md5
host gitea gitea 192.168.1.14/32 md5
host netbox netbox 192.168.1.45/32 md5
host authentik authentik 192.168.1.125/32 md5
host grafana grafana 192.168.1.27/32 md5
";
# Not great, not in prod, cleartext pass
# waiting for ensureUsers.*.passwordFile option
# https://github.com/NixOS/nixpkgs/pull/326306
2024-09-09 15:19:57 +02:00
initialScript = pkgs.writeText "init-sql-script" ''
2024-10-24 14:26:28 +02:00
alter user gitea with password 'password';
alter user nextcloud with password 'password';
2024-09-09 15:19:57 +02:00
'';
};
networking.firewall.allowedTCPPorts = [ 5432 ];
};
}