summary refs log tree commit diff
path: root/nixos/tests/miriway.nix
blob: d0d9f16d40f9583344a6508c5d181d891c85ed95 (plain) (blame)
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
import ./make-test-python.nix ({ pkgs, lib, ... }: {
  name = "miriway";

  meta = {
    maintainers = with lib.maintainers; [ OPNA2608 ];
    # Natively running Mir has problems with capturing the first registered libinput device.
    # In our VM  runners on ARM and on some hardware configs (my RPi4, distro-independent), this misses the keyboard.
    # It can be worked around by dis- and reconnecting the affected hardware, but we can't do this in these tests.
    # https://github.com/MirServer/mir/issues/2837
    broken = pkgs.stdenv.hostPlatform.isAarch;
  };

  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";
    };

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

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

        ctrl-alt=t:foot --maximized
        ctrl-alt=a:env WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty --option window.startup_mode=maximized

        shell-component=dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY

        shell-component=foot --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".text = lib.generators.toINI { } {
        main = {
          font = "inconsolata:size=16";
        };
        colors = rec {
          foreground = "000000";
          background = "ffffff";
          regular2 = foreground;
        };
      };
      etc."xdg/alacritty/alacritty.yml".text = lib.generators.toYAML { } {
        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.fonts = [ 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("alice@machine")
    machine.send_chars("test-wayland\n")
    machine.wait_for_file("/tmp/test-wayland-exit-ok")
    machine.copy_from_vm("/tmp/test-wayland.out")
    machine.screenshot("foot_wayland_info")
    # Only succeeds when a mouse is moved inside an interactive session?
    # machine.send_chars("exit\n")
    # machine.wait_until_fails("pgrep foot")
    machine.succeed("pkill foot")

    # Test XWayland
    machine.send_key("ctrl-alt-a")
    machine.wait_for_text("alice@machine")
    machine.send_chars("test-x11\n")
    machine.wait_for_file("/tmp/test-x11-exit-ok")
    machine.copy_from_vm("/tmp/test-x11.out")
    machine.screenshot("alacritty_glinfo")
    # Only succeeds when a mouse is moved inside an interactive session?
    # machine.send_chars("exit\n")
    # machine.wait_until_fails("pgrep alacritty")
    machine.succeed("pkill alacritty")
  '';
})