Skip to content

Commit

Permalink
nixos/tests/invidious: move postgres-tcp into second machine and fix …
Browse files Browse the repository at this point in the history
…tests

Using PostgreSQL 15 without the init script fails due to
NixOS#216989.
  • Loading branch information
999eagle authored and Lainera committed Dec 20, 2023
1 parent 2ce938a commit d3d7092
Showing 1 changed file with 44 additions and 40 deletions.
84 changes: 44 additions & 40 deletions nixos/tests/invidious.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
};
};
};
};
};
Expand All @@ -63,16 +66,17 @@ 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)
activate_specialisation("nginx")
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)
Expand Down

0 comments on commit d3d7092

Please sign in to comment.