From c34493d7c0a1edbcc028d34941f0807b5255f338 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 20 Jan 2024 17:33:00 +0100 Subject: ttyd: add test & use systemd LoadCredential --- nixos/modules/services/web-servers/ttyd.nix | 3 ++- nixos/tests/all-tests.nix | 1 + nixos/tests/web-servers/ttyd.nix | 19 +++++++++++++++++++ pkgs/servers/ttyd/default.nix | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/web-servers/ttyd.nix diff --git a/nixos/modules/services/web-servers/ttyd.nix b/nixos/modules/services/web-servers/ttyd.nix index 3b1d87ccb483..e545869ca432 100644 --- a/nixos/modules/services/web-servers/ttyd.nix +++ b/nixos/modules/services/web-servers/ttyd.nix @@ -180,10 +180,11 @@ in # Runs login which needs to be run as root # login: Cannot possibly work without effective root User = "root"; + LoadCredential = lib.optionalString (cfg.passwordFile != null) "TTYD_PASSWORD_FILE:${cfg.passwordFile}"; }; script = if cfg.passwordFile != null then '' - PASSWORD=$(cat ${escapeShellArg cfg.passwordFile}) + PASSWORD=$(cat "$CREDENTIALS_DIRECTORY/TTYD_PASSWORD_FILE") ${pkgs.ttyd}/bin/ttyd ${lib.escapeShellArgs args} \ --credential ${escapeShellArg cfg.username}:"$PASSWORD" \ ${pkgs.shadow}/bin/login diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 63e957eace88..7a2d560d3bc9 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -902,6 +902,7 @@ in { trilium-server = handleTestOn ["x86_64-linux"] ./trilium-server.nix {}; tsja = handleTest ./tsja.nix {}; tsm-client-gui = handleTest ./tsm-client-gui.nix {}; + ttyd = handleTest ./web-servers/ttyd.nix {}; txredisapi = handleTest ./txredisapi.nix {}; tuptime = handleTest ./tuptime.nix {}; turbovnc-headless-server = handleTest ./turbovnc-headless-server.nix {}; diff --git a/nixos/tests/web-servers/ttyd.nix b/nixos/tests/web-servers/ttyd.nix new file mode 100644 index 000000000000..d161673684b3 --- /dev/null +++ b/nixos/tests/web-servers/ttyd.nix @@ -0,0 +1,19 @@ +import ../make-test-python.nix ({ lib, pkgs, ... }: { + name = "ttyd"; + meta.maintainers = with lib.maintainers; [ stunkymonkey ]; + + nodes.machine = { pkgs, ... }: { + services.ttyd = { + enable = true; + username = "foo"; + passwordFile = pkgs.writeText "password" "bar"; + }; + }; + + testScript = '' + machine.wait_for_unit("ttyd.service") + machine.wait_for_open_port(7681) + response = machine.succeed("curl -vvv -u foo:bar -s -H 'Host: ttyd' http://127.0.0.1:7681/") + assert 'ttyd - Terminal' in response, "Page didn't load successfully" + ''; +}) diff --git a/pkgs/servers/ttyd/default.nix b/pkgs/servers/ttyd/default.nix index 9741a23f9851..68731b6f717d 100644 --- a/pkgs/servers/ttyd/default.nix +++ b/pkgs/servers/ttyd/default.nix @@ -20,6 +20,10 @@ stdenv.mkDerivation rec { outputs = [ "out" "man" ]; + passthru.tests = { + inherit (nixosTests) ttyd; + }; + meta = { description = "Share your terminal over the web"; homepage = "https://github.com/tsl0922/ttyd"; -- cgit 1.4.1