summaryrefslogtreecommitdiffstats
path: root/nixos/tests/miriway.nix
blob: d5b146ed6dc5115bd539cfcc50802cee52f49ab0 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{ pkgs, lib, ... }:
{
  name = "miriway";

  meta = {
    maintainers = with lib.maintainers; [ OPNA2608 ];
  };

  nodes.machine =
    { config, ... }:
    {
      imports = [
        ./common/auto.nix
        ./common/user-account.nix
      ];

      # Seems to very rarely get interrupted by oom-killer
      virtualisation.memorySize = 2047;

      test-support.displayManager.auto = {
        enable = true;
        user = "alice";
      };

      programs.ydotool.enable = true;

      services.xserver.enable = true;
      services.displayManager.defaultSession = lib.mkForce "miriway";

      programs.miriway = {
        enable = true;
        config = ''
          add-wayland-extensions=all
          enable-x11=

          shell-component=foot --maximized
        '';
        settings = ''
          command_ctrl_alt=t:foot --maximized
          command_ctrl_alt=a:env WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty --option window.startup_mode=\"maximized\"
        '';
      };

      environment = {
        shellAliases = {
          test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
          test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
        };

        systemPackages = with pkgs; [
          mesa-demos
          wayland-utils
          foot
          alacritty
        ];

        # To help with OCR
        etc."xdg/foot/foot.ini".source = (pkgs.formats.ini { }).generate "foot.ini" {
          main = {
            font = "inconsolata:size=16";
            initial-color-theme = "light";
          };
          colors-light = rec {
            foreground = "000000";
            background = "ffffff";
            regular2 = foreground;
          };
        };
        etc."xdg/alacritty/alacritty.toml".source = (pkgs.formats.toml { }).generate "alacritty.toml" {
          font = rec {
            normal.family = "Inconsolata";
            bold.family = normal.family;
            italic.family = normal.family;
            bold_italic.family = normal.family;
            size = 16;
          };
          colors = rec {
            primary = {
              foreground = "0x000000";
              background = "0xffffff";
            };
            normal = {
              green = primary.foreground;
            };
          };
        };
      };

      fonts.packages = [ pkgs.inconsolata ];
    };

  enableOCR = true;

  testScript =
    { nodes, ... }:
    ''
      start_all()
      machine.wait_for_unit("multi-user.target")

      # Wait for Miriway to complete startup
      machine.wait_for_file("/run/user/1000/wayland-0")
      machine.succeed("pgrep miriway-shell")
      machine.screenshot("miriway_launched")

      # Test Wayland
      # We let Miriway start the first terminal, as we might get stuck if it's not ready to process the first keybind
      # machine.send_key("ctrl-alt-t")
      machine.wait_for_text(r"(alice|machine)")
      machine.send_chars("test-wayland\n")
      machine.wait_for_file("/tmp/test-wayland-exit-ok")
      machine.copy_from_machine("/tmp/test-wayland.out")
      machine.screenshot("foot_wayland_info")

      # please actually register that we want to close the window
      machine.succeed("ydotool mousemove -- 10 10")
      machine.sleep(3)

      machine.send_chars("exit\n")

      # please actually register that we want to close the window
      machine.succeed("ydotool mousemove -- 10 10")
      machine.sleep(3)

      machine.wait_until_fails("pgrep foot")

      # Test XWayland
      machine.send_key("ctrl-alt-a")
      machine.wait_for_text(r"(alice|machine)")
      machine.send_chars("test-x11\n")
      machine.wait_for_file("/tmp/test-x11-exit-ok")
      machine.copy_from_machine("/tmp/test-x11.out")
      machine.screenshot("alacritty_glinfo")

      # please actually register that we want to close the window
      machine.succeed("ydotool mousemove -- 10 10")
      machine.sleep(3)

      machine.send_chars("exit\n")

      # please actually register that we want to close the window
      machine.succeed("ydotool mousemove -- 10 10")
      machine.sleep(3)

      machine.wait_until_fails("pgrep alacritty")
    '';
}