{
  lib,
  pkgs,
  ...
}:

{
  name = "Repath Studio";

  nodes = {
    machine =
      { pkgs, ... }:
      {
        imports = [
          # enable graphical session + users (alice, bob)
          ./common/x11.nix
          ./common/user-account.nix
        ];

        services.xserver.enable = true;
        test-support.displayManager.auto.user = "alice";

        environment.systemPackages = with pkgs; [
          xdotool
          repath-studio
        ];

        # electron application, give more memory and cpu
        virtualisation.memorySize = 4096;
        virtualisation.cores = 4;
        virtualisation.qemu.options = [
          # Force qemu at 1020x768 resolution for the Save button click
          "-vga none -device virtio-gpu-pci,xres=1020,yres=768"
        ];
      };
  };

  enableOCR = true;

  # Debug interactively with:
  # - nix run .#nixosTests.repath-studio.driverInteractive -L
  # - start_all()/run_tests()
  interactive.sshBackdoor.enable = true;

  testScript = /* python */ ''
    start_all()

    machine.wait_for_x()
    machine.succeed("env DISPLAY=:0 sudo -u alice repath-studio &> /tmp/repath.log &")
    machine.wait_for_text(r"(Welcome|Repath|Studio)") # initial telemetry prompt

    machine.screenshot("Repath-Studio-GUI-Welcome")
    machine.send_key("kp_enter") # OK

    # sleep is required it needs time to dismiss the dialog
    machine.sleep(2)
    machine.send_key("ctrl-shift-s")
    machine.sleep(2)
    machine.send_chars("/tmp/saved.rps")
    machine.sleep(2)
    machine.succeed("su - alice -c 'DISPLAY=:0 xdotool mousemove --sync 975 745 click 1'") # Save file dialog
    machine.sleep(2)
    print(machine.succeed("cat /tmp/saved.rps"))
    assert "${pkgs.repath-studio.version}" in machine.succeed("cat /tmp/saved.rps")

    machine.screenshot("Repath-Studio-GUI")
  '';

  meta.maintainers = lib.teams.ngi.members;
}
