From 8a181e033cd1dfef17caf9b0d1b7085c768010f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20H=C3=A4ring?= Date: Fri, 13 Mar 2026 17:23:36 +0100 Subject: [PATCH] nixos/stirling-pdf: add integration tests Co-authored-by: phanirithvij --- .../services/web-apps/stirling-pdf.nix | 7 +- nixos/tests/all-tests.nix | 1 + nixos/tests/stirling-pdf-desktop.nix | 131 ++++++++++++++++++ pkgs/by-name/st/stirling-pdf/package.nix | 6 +- 4 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 nixos/tests/stirling-pdf-desktop.nix diff --git a/nixos/modules/services/web-apps/stirling-pdf.nix b/nixos/modules/services/web-apps/stirling-pdf.nix index 52b9c084cdd1..305d482053de 100644 --- a/nixos/modules/services/web-apps/stirling-pdf.nix +++ b/nixos/modules/services/web-apps/stirling-pdf.nix @@ -19,12 +19,13 @@ in lib.types.oneOf [ lib.types.str lib.types.int + lib.types.bool ] ); default = { }; example = { SERVER_PORT = 8080; - INSTALL_BOOK_AND_ADVANCED_HTML_OPS = "true"; + INSTALL_BOOK_AND_ADVANCED_HTML_OPS = true; }; description = '' Environment variables for the stirling-pdf app. @@ -44,7 +45,9 @@ in config = lib.mkIf cfg.enable { systemd.services.stirling-pdf = { - environment = lib.mapAttrs (_: toString) cfg.environment; + environment = lib.mapAttrs ( + _: v: if (builtins.isBool v) then (lib.boolToString v) else (toString v) + ) cfg.environment; # following https://docs.stirlingpdf.com/Installation/Unix%20Installation path = diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 32c49bf3a0e9..a938e82ec6a9 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1507,6 +1507,7 @@ in stash = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./stash.nix { }; static-web-server = runTest ./web-servers/static-web-server.nix; step-ca = handleTestOn [ "x86_64-linux" ] ./step-ca.nix { }; + stirling-pdf-desktop = runTest ./stirling-pdf-desktop.nix; stratis = handleTest ./stratis { }; strongswan-swanctl = runTest ./strongswan-swanctl.nix; stub-ld = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./stub-ld.nix { }; diff --git a/nixos/tests/stirling-pdf-desktop.nix b/nixos/tests/stirling-pdf-desktop.nix new file mode 100644 index 000000000000..bf32496bf922 --- /dev/null +++ b/nixos/tests/stirling-pdf-desktop.nix @@ -0,0 +1,131 @@ +{ lib, hostPkgs, ... }: +let + port = 8080; + server = "http://server:${toString port}"; +in +{ + name = "stirling-pdf"; + meta = { + maintainers = with lib.maintainers; [ + timhae + phanirithvij + ]; + }; + + enableOCR = true; + globalTimeout = 600; + nodes = { + server = + { config, pkgs, ... }: + { + services.stirling-pdf = { + enable = true; + package = pkgs.stirling-pdf; + environment = { + SERVER_PORT = port; + DISABLE_ADDITIONAL_FEATURES = false; + SECURITY_ENABLELOGIN = true; + }; + }; + networking.firewall.allowedTCPPorts = [ port ]; + }; + client = + { config, pkgs, ... }: + { + virtualisation = { + memorySize = 4096; + cores = 4; + qemu.options = [ + # Force qemu at 640x480 resolution + "-vga none -device virtio-gpu-pci,xres=640,yres=480" + ]; + }; + imports = [ ./common/wayland-cage.nix ]; + services.cage.program = lib.getExe pkgs.stirling-pdf-desktop; + systemd.tmpfiles.settings."stirling-provisioning.json"."/etc/stirling-pdf/stirling-provisioning.json"."L+".argument = + builtins.toString ( + pkgs.writeText "stirling-provisioning.json" '' + { + "serverUrl": "${server}", + "lockConnectionMode": true + } + '' + ); + programs.ydotool.enable = true; + users.users.alice.extraGroups = [ "ydotool" ]; + }; + }; + + testScript = '' + server.start() + server.wait_for_unit("stirling-pdf.service") + server.wait_for_console_text("Stirling-PDF Started") + + # initial login + client.start() + client.wait_for_text("Sign in to Server") + client.send_chars("admin", 0.1) + client.send_key("tab", 1) + client.send_chars("stirling\n", 0.1) + + # skip telemetry prompt + client.wait_for_text("analytics") + client.send_key("shift-tab", 1) + client.send_key("tab", 1) + client.send_key("tab", 1) + client.send_key("kp_enter", 1) + + # update password + client.wait_for_text("password") + client.send_key("tab", 1) + client.send_key("shift-tab", 1) + client.send_key("shift-tab", 1) + client.send_key("shift-tab", 1) + client.send_chars("stirling2", 0.1) + client.send_key("tab", 1) + client.send_chars("stirling2", 0.1) + client.send_key("tab", 1) + client.send_key("kp_enter", 1) + + # final login + client.wait_for_text("Sign in to Server") + client.send_chars("admin", 0.1) + client.send_key("tab", 1) + client.send_chars("stirling2\n", 0.1) + client.wait_for_text("Welcome to Stirling") + client.send_key("kp_enter", 1) + + # version prompt + client.wait_for_text("Config") + client.execute("ydotool mousemove -a -- 290 220") # Config button + client.execute("ydotool click 0xC0") + client.wait_for_text("Current Frontend Version") + client.screenshot("stirling-pdf-version") + ''; + + # Debug interactively with: + # - nix-build -A nixosTests.stirling-pdf-desktop.driverInteractive + # - ./result/bin/nixos-test-driver + # - run_tests() + # ssh -o User=root vsock%3 (can also do vsock/3, but % works with scp etc.) + interactive.sshBackdoor.enable = true; + interactive.nodes.client = + { pkgs, ... }: + { + # make the mouse visible + services.cage.environment.WLR_NO_HARDWARE_CURSORS = "1"; + }; + interactive.nodes.server = + { ... }: + { + virtualisation.forwardPorts = [ + { + from = "host"; + host.port = port; + guest.port = port; + } + ]; + # forwarded ports need to be accessible + networking.firewall.allowedTCPPorts = [ port ]; + }; +} diff --git a/pkgs/by-name/st/stirling-pdf/package.nix b/pkgs/by-name/st/stirling-pdf/package.nix index d102f803255d..0531186d2048 100644 --- a/pkgs/by-name/st/stirling-pdf/package.nix +++ b/pkgs/by-name/st/stirling-pdf/package.nix @@ -21,6 +21,7 @@ webkitgtk_4_1, nix-update-script, + nixosTests, isDesktopVariant ? false, buildWithFrontend ? !isDesktopVariant, @@ -166,7 +167,10 @@ stdenv.mkDerivation (finalAttrs: { ln -s ${jre} "$res_dir/runtime/jre" ''; - passthru.updateScript = nix-update-script { }; + passthru = { + updateScript = nix-update-script { }; + tests = { inherit (nixosTests) stirling-pdf-desktop; }; + }; meta = { changelog = "https://github.com/Stirling-Tools/Stirling-PDF/releases/tag/v${finalAttrs.version}";