From 5b346a93fc96e0971976753dafa5b6741bad1ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Tue, 19 Nov 2024 08:26:32 +0100 Subject: [PATCH] add postgresql --- services/postgresql/default.nix | 30 ++++++++++++++++++++++++++++++ services/postgresql/pgbouncer.nix | 14 ++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 services/postgresql/default.nix create mode 100644 services/postgresql/pgbouncer.nix diff --git a/services/postgresql/default.nix b/services/postgresql/default.nix new file mode 100644 index 00000000..31f8f15a --- /dev/null +++ b/services/postgresql/default.nix @@ -0,0 +1,30 @@ +{ + config, + pkgs, + lib, + ... +}: +{ + imports = [ + ./pgbouncer.nix + ]; + services.postgresql = { + enable = true; + enableJIT = true; + enableTCPIP = true; + package = pkgs.postgresql_17_jit; + authentication = lib.mkForce '' + local all all trust + host all all 127.0.0.1 scram-sha-256 + ''; + }; + services.postgresqlBackup = { + compression = "zstd"; + compressionLevel = 19; + enable = true; + }; + environment.persistence."/persistent".directories = [ + "${config.postgresql.dataDir}" + "${config.postgresqlLocation.location}" + ]; +} diff --git a/services/postgresql/pgbouncer.nix b/services/postgresql/pgbouncer.nix new file mode 100644 index 00000000..9e20cb68 --- /dev/null +++ b/services/postgresql/pgbouncer.nix @@ -0,0 +1,14 @@ +{ config, ... }: +{ + services.pgbouncer = { + enable = true; + settings = { + pgbouncer = { + listen_addr = "localhost"; + auth_type = "scram-sha-256"; + auth_file = config.sops.secrets."services/pgbouncer/settings/pgbouncer/auth".path; + }; + }; + }; + sops.secrets."services/pgbouncer/settings/pgbouncer/auth".sopsFile = ./${config.networking.hostName}.yaml; +}