summaryrefslogtreecommitdiffstats
path: root/nixos/tests/sunshine.nix
blob: 80f8e96b89eb500bc16bc5121b7a1bcb86c7347d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ pkgs, lib, ... }:
{
  name = "sunshine";
  meta = {
    # test is flaky on aarch64
    broken = pkgs.stdenv.hostPlatform.isAarch64;
    maintainers = [ lib.maintainers.devusb ];
    timeout = 600;
  };

  nodes.sunshine =
    { config, pkgs, ... }:
    {
      imports = [
        ./common/x11.nix
      ];

      virtualisation.memorySize = 4096;

      services.sunshine = {
        enable = true;
        openFirewall = true;
        settings = {
          capture = "x11";
          encoder = "software";
          output_name = 0;
        };
      };

      environment.systemPackages = with pkgs; [
        gxmessage
      ];

    };

  nodes.moonlight =
    { config, pkgs, ... }:
    {
      imports = [
        ./common/x11.nix
      ];

      programs.moonlight-qt = {
        enable = true;
        capSysNice = true;
      };

    };

  enableOCR = true;

  testScript = ''
    # start the tests, wait for sunshine to be up
    start_all()
    sunshine.wait_for_open_port(48010,"localhost")
    moonlight.succeed("${pkgs.libcap}/bin/getcap \"$(command -v moonlight)\" | grep -q 'cap_sys_nice'")

    # set the admin username/password, restart sunshine
    sunshine.execute("sunshine --creds sunshine sunshine")
    sunshine.systemctl("restart sunshine","root")
    sunshine.wait_for_open_port(48010,"localhost")

    # initiate pairing from moonlight
    moonlight.execute("moonlight pair sunshine --pin 1234 >&2 & disown")
    moonlight.wait_for_console_text("Executing request.*pair")

    # respond to pairing request from sunshine
    sunshine.succeed("curl --fail --insecure -u sunshine:sunshine -H 'Content-Type: application/json' -d '{\"pin\":\"1234\",\"name\":\"sunshine\"}' https://localhost:47990/api/pin")

    # wait until pairing is complete
    moonlight.wait_for_console_text("Executing request.*phrase=pairchallenge")

    # hide icewm panel
    sunshine.send_key("ctrl-alt-h")
    # put words on the sunshine screen for moonlight to see
    sunshine.execute("gxmessage ' ABC' -center -font 'consolas 100' -fg '#FFFFFF' -bg '#000000' -borderless -geometry '2000x2000' -buttons \"\" >&2 & disown")

    # connect to sunshine from moonlight and look for the words
    moonlight.execute("moonlight --video-decoder software stream sunshine 'Desktop' >&2 & disown")
    moonlight.wait_for_console_text("Dropping window event during flush")
    moonlight.wait_for_text("ABC")
  '';
}