diff options
| author | Isabella Bastaja <isabella@sorre.xyz> | 2026-08-20 22:47:24 +0200 |
|---|---|---|
| committer | Isabella Bastaja <isabella@sorre.xyz> | 2026-08-20 22:48:29 +0200 |
| commit | 433ac8ba6ecfcc4295b65c41b2e6fb88eef0c447 (patch) | |
| tree | 2183a56a4750fb61bcc46931f33cacb2b7aeb08f /hosts/tower/postgres.nix | |
| parent | 6141d0081042556d3a79ad3a047bf4f2325e5038 (diff) | |
tower: set up postgres
Diffstat (limited to 'hosts/tower/postgres.nix')
| -rw-r--r-- | hosts/tower/postgres.nix | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hosts/tower/postgres.nix b/hosts/tower/postgres.nix new file mode 100644 index 0000000..67c9fdd --- /dev/null +++ b/hosts/tower/postgres.nix @@ -0,0 +1,50 @@ +{ + pkgs, + lib, + config, + ... +}: +let + newPostgres = pkgs.postgresql_18_jit; + cfg = config.services.postgresql; + upgrade-pg-cluster = pkgs.writeScriptBin "upgrade-pg-cluster" '' + set -eux + systemctl stop postgresql + + export NEWDATA="/var/lib/postgresql/${newPostgres.psqlSchema}" + export NEWBIN="${newPostgres}/bin" + + export OLDDATA="${cfg.dataDir}" + export OLDBIN="${cfg.finalPackage}/bin" + + install -d -m 0700 -o postgres -g postgres "$NEWDATA" + cd "$NEWDATA" + sudo -u postgres "$NEWBIN/initdb" -D "$NEWDATA" ${lib.escapeShellArgs cfg.initdbArgs} + + sudo -u postgres "$NEWBIN/pg_upgrade" \ + --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \ + --old-bindir "$OLDBIN" --new-bindir "$NEWBIN" \ + "$@" + ''; +in +{ + services.postgresql = { + enable = true; + package = pkgs.postgresql_18_jit; + enableTCPIP = true; + enableJIT = true; + + settings = { + password_encryption = "scram-sha-256"; + }; + + authentication = '' + # TYPE DATABASE USER ADDRESS METHOD + local all all peer + host all postgres all reject + host all all all scram-sha-256 + ''; + }; # end of services.postgreslq + + environment.systemPackages = [ upgrade-pg-cluster ]; +} |
