nixos/tests/invidious: move postgres-tcp into second machine and fix tests

Using PostgreSQL 15 without the init script fails due to
https://github.com/NixOS/nixpkgs/issues/216989.

+44 -40
+44 -40
nixos/tests/invidious.nix
··· 5 maintainers = [ sbruder ]; 6 }; 7 8 - nodes.machine = { config, lib, pkgs, ... }: { 9 - services.invidious = { 10 - enable = true; 11 }; 12 - 13 - specialisation = { 14 - nginx.configuration = { 15 - services.invidious = { 16 - nginx.enable = true; 17 - domain = "invidious.example.com"; 18 - }; 19 - services.nginx.virtualHosts."invidious.example.com" = { 20 - forceSSL = false; 21 - enableACME = false; 22 - }; 23 - networking.hosts."127.0.0.1" = [ "invidious.example.com" ]; 24 }; 25 - postgres-tcp.configuration = { 26 - services.invidious = { 27 - database = { 28 - createLocally = false; 29 - host = "127.0.0.1"; 30 - passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple"); 31 }; 32 }; 33 - # Normally not needed because when connecting to postgres over TCP/IP 34 - # the database is most likely on another host. 35 - systemd.services.invidious = { 36 - after = [ "postgresql.service" ]; 37 - requires = [ "postgresql.service" ]; 38 - }; 39 - services.postgresql = 40 - let 41 - inherit (config.services.invidious.settings.db) dbname user; 42 - in 43 - { 44 - enable = true; 45 - initialScript = pkgs.writeText "init-postgres-with-password" '' 46 - CREATE USER kemal WITH PASSWORD 'correct horse battery staple'; 47 - CREATE DATABASE invidious OWNER kemal; 48 - ''; 49 }; 50 }; 51 }; 52 }; ··· 63 url = "http://localhost:${toString nodes.machine.config.services.invidious.port}" 64 port = ${toString nodes.machine.config.services.invidious.port} 65 66 machine.wait_for_open_port(port) 67 curl_assert_status_code(f"{url}/search", 200) 68 ··· 70 machine.wait_for_open_port(80) 71 curl_assert_status_code("http://invidious.example.com/search", 200) 72 73 - # Remove the state so the `initialScript` gets run 74 - machine.succeed("systemctl stop postgresql") 75 - machine.succeed("rm -r /var/lib/postgresql") 76 activate_specialisation("postgres-tcp") 77 machine.wait_for_open_port(port) 78 curl_assert_status_code(f"{url}/search", 200)
··· 5 maintainers = [ sbruder ]; 6 }; 7 8 + nodes = { 9 + postgres-tcp = { config, pkgs, ... }: { 10 + services.postgresql = { 11 + enable = true; 12 + initialScript = pkgs.writeText "init-postgres-with-password" '' 13 + CREATE USER kemal WITH PASSWORD 'correct horse battery staple'; 14 + CREATE DATABASE invidious WITH OWNER kemal; 15 + ''; 16 + enableTCPIP = true; 17 + authentication = '' 18 + host invidious kemal samenet scram-sha-256 19 + ''; 20 + }; 21 + networking.firewall.allowedTCPPorts = [ config.services.postgresql.port ]; 22 }; 23 + machine = { config, lib, pkgs, ... }: { 24 + services.invidious = { 25 + enable = true; 26 }; 27 + services.postgresql.initialScript = pkgs.writeText "init-postgres-with-password" '' 28 + CREATE USER kemal; 29 + CREATE DATABASE invidious WITH OWNER kemal; 30 + ''; 31 + 32 + specialisation = { 33 + nginx.configuration = { 34 + services.invidious = { 35 + nginx.enable = true; 36 + domain = "invidious.example.com"; 37 }; 38 + services.nginx.virtualHosts."invidious.example.com" = { 39 + forceSSL = false; 40 + enableACME = false; 41 + }; 42 + networking.hosts."127.0.0.1" = [ "invidious.example.com" ]; 43 }; 44 + postgres-tcp.configuration = { 45 + services.invidious = { 46 + database = { 47 + createLocally = false; 48 + host = "postgres-tcp"; 49 + passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple"); 50 + }; 51 }; 52 + }; 53 }; 54 }; 55 }; ··· 66 url = "http://localhost:${toString nodes.machine.config.services.invidious.port}" 67 port = ${toString nodes.machine.config.services.invidious.port} 68 69 + # start postgres vm now 70 + postgres_tcp.start() 71 + 72 machine.wait_for_open_port(port) 73 curl_assert_status_code(f"{url}/search", 200) 74 ··· 76 machine.wait_for_open_port(80) 77 curl_assert_status_code("http://invidious.example.com/search", 200) 78 79 + postgres_tcp.wait_for_unit("postgresql.service") 80 activate_specialisation("postgres-tcp") 81 machine.wait_for_open_port(port) 82 curl_assert_status_code(f"{url}/search", 200)