From ca4316aadf41fa9fbe0238fff59fa78972a47a95 Mon Sep 17 00:00:00 2001 From: James Hollowell Date: Sun, 30 Nov 2025 16:39:19 -0500 Subject: [PATCH 1/2] nixos/tests/ersatz: migrate to runTest --- nixos/tests/all-tests.nix | 2 +- nixos/tests/ersatztv.nix | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9902d3e7e686..e54cceea4f2d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -522,7 +522,7 @@ in }; ergo = runTest ./ergo.nix; ergochat = runTest ./ergochat.nix; - ersatztv = handleTest ./ersatztv.nix { }; + ersatztv = runTest ./ersatztv.nix; espanso = import ./espanso.nix { inherit (pkgs) lib; inherit runTest; diff --git a/nixos/tests/ersatztv.nix b/nixos/tests/ersatztv.nix index 0924579a74d9..9bc179dfc697 100644 --- a/nixos/tests/ersatztv.nix +++ b/nixos/tests/ersatztv.nix @@ -1,21 +1,19 @@ -import ./make-test-python.nix ( - { lib, ... }: +{ lib, ... }: - { - name = "ersatztv"; - meta.maintainers = with lib.maintainers; [ allout58 ]; +{ + name = "ersatztv"; + meta.maintainers = with lib.maintainers; [ allout58 ]; - nodes.machine = - { ... }: - { - services.ersatztv.enable = true; - }; + nodes.machine = + { ... }: + { + services.ersatztv.enable = true; + }; - # ErsatzTV doesn't really have an API to speak of currently, so just check if it responds at all - testScript = '' - machine.wait_for_unit("ersatztv.service") - machine.wait_for_open_port(8409) - machine.succeed("curl --fail http://localhost:8409/") - ''; - } -) + # ErsatzTV doesn't really have an API to speak of currently, so just check if it responds at all + testScript = '' + machine.wait_for_unit("ersatztv.service") + machine.wait_for_open_port(8409) + machine.succeed("curl --fail http://localhost:8409/") + ''; +} From 8a26a5c546a2172afef6888b03e2637f880e756c Mon Sep 17 00:00:00 2001 From: James Hollowell Date: Mon, 24 Nov 2025 21:46:33 -0500 Subject: [PATCH 2/2] nixos/ersatztv: fix mismatch between environment type firewall port services.ersatztv.environment must not have number types, but networking.firewall.allowedTCPPorts must be an integer Updates nixosTests.ersatztv to test setting new UI port --- nixos/modules/services/misc/ersatztv.nix | 6 ++++- nixos/tests/ersatztv.nix | 34 +++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/misc/ersatztv.nix b/nixos/modules/services/misc/ersatztv.nix index e32a224241f0..faba7cc1d8e6 100644 --- a/nixos/modules/services/misc/ersatztv.nix +++ b/nixos/modules/services/misc/ersatztv.nix @@ -20,12 +20,14 @@ let bool float int + package ; cfg = config.services.ersatztv; defaultEnv = { ETV_UI_PORT = 8409; ETV_BASE_URL = "/"; }; + in { options = { @@ -54,6 +56,8 @@ in int float bool + path + package ]); default = defaultEnv; example = { @@ -108,7 +112,7 @@ in ETV_CONFIG_FOLDER = "/var/lib/ersatztv/config"; ETV_TRANSCODE_FOLDER = "/var/lib/ersatztv/transcode"; } - // cfg.environment; + // (lib.mapAttrs (_: s: if lib.isBool s then lib.boolToString s else toString s) cfg.environment); }; }; diff --git a/nixos/tests/ersatztv.nix b/nixos/tests/ersatztv.nix index 9bc179dfc697..12a41e19c9aa 100644 --- a/nixos/tests/ersatztv.nix +++ b/nixos/tests/ersatztv.nix @@ -4,16 +4,38 @@ name = "ersatztv"; meta.maintainers = with lib.maintainers; [ allout58 ]; - nodes.machine = + nodes.basic = { ... }: { services.ersatztv.enable = true; }; + nodes.reconfigured = + { ... }: + { + services.ersatztv.enable = true; + services.ersatztv.environment.ETV_UI_PORT = 8123; + services.ersatztv.openFirewall = true; + }; # ErsatzTV doesn't really have an API to speak of currently, so just check if it responds at all - testScript = '' - machine.wait_for_unit("ersatztv.service") - machine.wait_for_open_port(8409) - machine.succeed("curl --fail http://localhost:8409/") - ''; + testScript = + { nodes, ... }: + let + basicIp = (lib.head nodes.basic.networking.interfaces.eth1.ipv4.addresses).address; + reconfiguredIp = (lib.head nodes.reconfigured.networking.interfaces.eth1.ipv4.addresses).address; + in + '' + start_all() + basic.wait_for_unit("ersatztv.service") + basic.wait_for_open_port(8409) + basic.succeed("curl --fail http://localhost:8409/api/sessions") + + reconfigured.wait_for_unit("ersatztv.service") + reconfigured.wait_for_open_port(8123) + reconfigured.succeed("curl --fail http://localhost:8123/api/sessions") + + # Test that the firewall is open + reconfigured.fail("curl --fail --connect-timeout 5 http://${basicIp}:8409/api/sessions") + basic.succeed("curl --fail http://${reconfiguredIp}:8123/api/sessions") + ''; }