about summary refs log tree commit diff
path: root/nixos/tests/invidious.nix
diff options
context:
space:
mode:
authorSophie Tauchert <sophie@999eagle.moe>2023-11-06 14:23:24 +0100
committerSophie Tauchert <sophie@999eagle.moe>2023-12-17 19:48:02 +0100
commit460e34b273592fb6b4fa7e57d65c02c82895d03a (patch)
tree016639341f40b9588150be663098ec5d9986dcfc /nixos/tests/invidious.nix
parent4a7faeaff38e1a5036a77dcbebd14d09dcf3cd5d (diff)
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.
Diffstat (limited to 'nixos/tests/invidious.nix')
-rw-r--r--nixos/tests/invidious.nix84
1 files changed, 44 insertions, 40 deletions
diff --git a/nixos/tests/invidious.nix b/nixos/tests/invidious.nix
index 701e8e5e7a3fc..5be7270bc1dc3 100644
--- a/nixos/tests/invidious.nix
+++ b/nixos/tests/invidious.nix
@@ -5,48 +5,51 @@ import ./make-test-python.nix ({ pkgs, ... }: {
     maintainers = [ sbruder ];
   };
 
-  nodes.machine = { config, lib, pkgs, ... }: {
-    services.invidious = {
-      enable = true;
+  nodes = {
+    postgres-tcp = { config, pkgs, ... }: {
+      services.postgresql = {
+        enable = true;
+        initialScript = pkgs.writeText "init-postgres-with-password" ''
+          CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
+          CREATE DATABASE invidious WITH OWNER kemal;
+        '';
+        enableTCPIP = true;
+        authentication = ''
+          host invidious kemal samenet scram-sha-256
+        '';
+      };
+      networking.firewall.allowedTCPPorts = [ config.services.postgresql.port ];
     };
-
-    specialisation = {
-      nginx.configuration = {
-        services.invidious = {
-          nginx.enable = true;
-          domain = "invidious.example.com";
-        };
-        services.nginx.virtualHosts."invidious.example.com" = {
-          forceSSL = false;
-          enableACME = false;
-        };
-        networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
+    machine = { config, lib, pkgs, ... }: {
+      services.invidious = {
+        enable = true;
       };
-      postgres-tcp.configuration = {
-        services.invidious = {
-          database = {
-            createLocally = false;
-            host = "127.0.0.1";
-            passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
+      services.postgresql.initialScript = pkgs.writeText "init-postgres-with-password" ''
+        CREATE USER kemal;
+        CREATE DATABASE invidious WITH OWNER kemal;
+      '';
+
+      specialisation = {
+        nginx.configuration = {
+          services.invidious = {
+            nginx.enable = true;
+            domain = "invidious.example.com";
           };
+          services.nginx.virtualHosts."invidious.example.com" = {
+            forceSSL = false;
+            enableACME = false;
+          };
+          networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
         };
-        # Normally not needed because when connecting to postgres over TCP/IP
-        # the database is most likely on another host.
-        systemd.services.invidious = {
-          after = [ "postgresql.service" ];
-          requires = [ "postgresql.service" ];
-        };
-        services.postgresql =
-          let
-            inherit (config.services.invidious.settings.db) dbname user;
-          in
-          {
-            enable = true;
-            initialScript = pkgs.writeText "init-postgres-with-password" ''
-              CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
-              CREATE DATABASE invidious OWNER kemal;
-            '';
+        postgres-tcp.configuration = {
+          services.invidious = {
+            database = {
+              createLocally = false;
+              host = "postgres-tcp";
+              passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
+            };
           };
+        };
       };
     };
   };
@@ -63,6 +66,9 @@ import ./make-test-python.nix ({ pkgs, ... }: {
     url = "http://localhost:${toString nodes.machine.config.services.invidious.port}"
     port = ${toString nodes.machine.config.services.invidious.port}
 
+    # start postgres vm now
+    postgres_tcp.start()
+
     machine.wait_for_open_port(port)
     curl_assert_status_code(f"{url}/search", 200)
 
@@ -70,9 +76,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
     machine.wait_for_open_port(80)
     curl_assert_status_code("http://invidious.example.com/search", 200)
 
-    # Remove the state so the `initialScript` gets run
-    machine.succeed("systemctl stop postgresql")
-    machine.succeed("rm -r /var/lib/postgresql")
+    postgres_tcp.wait_for_unit("postgresql.service")
     activate_specialisation("postgres-tcp")
     machine.wait_for_open_port(port)
     curl_assert_status_code(f"{url}/search", 200)