From 433ac8ba6ecfcc4295b65c41b2e6fb88eef0c447 Mon Sep 17 00:00:00 2001 From: Isabella Bastaja Date: Thu, 20 Aug 2026 22:47:24 +0200 Subject: tower: set up postgres --- hosts/tower/default.nix | 1 + hosts/tower/postgres.nix | 50 +++++++++++++++++++++++++++++++++++++++++++++ hosts/tower/web/default.nix | 1 - hosts/tower/web/mediadb.nix | 50 --------------------------------------------- 4 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 hosts/tower/postgres.nix delete mode 100644 hosts/tower/web/mediadb.nix (limited to 'hosts/tower') diff --git a/hosts/tower/default.nix b/hosts/tower/default.nix index ce72046..2fbfc6e 100644 --- a/hosts/tower/default.nix +++ b/hosts/tower/default.nix @@ -6,6 +6,7 @@ ./ssh.nix ./web ./network.nix + ./postgres.nix ]; boot.loader.systemd-boot.enable = true; 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 ]; +} diff --git a/hosts/tower/web/default.nix b/hosts/tower/web/default.nix index 9a68dc8..13ec615 100644 --- a/hosts/tower/web/default.nix +++ b/hosts/tower/web/default.nix @@ -2,7 +2,6 @@ { imports = [ # ./blog.nix - # ./mediadb.nix ./git.nix # ./static.nix # ./navidrome.nix diff --git a/hosts/tower/web/mediadb.nix b/hosts/tower/web/mediadb.nix deleted file mode 100644 index 67c9fdd..0000000 --- a/hosts/tower/web/mediadb.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ - 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 ]; -} -- cgit v1.3.1