1{ pkgs, lib, ... }:
2{
3 name = "miracle-wm";
4
5 meta = {
6 maintainers = with lib.maintainers; [ OPNA2608 ];
7 };
8
9 nodes.machine =
10 { config, ... }:
11 {
12 imports = [
13 ./common/auto.nix
14 ./common/user-account.nix
15 ];
16
17 # Seems to very rarely get interrupted by oom-killer
18 virtualisation.memorySize = 2047;
19
20 test-support.displayManager.auto = {
21 enable = true;
22 user = "alice";
23 };
24
25 programs.ydotool.enable = true;
26
27 services.xserver.enable = true;
28 services.displayManager.defaultSession = lib.mkForce "miracle-wm";
29
30 programs.wayland.miracle-wm.enable = true;
31
32 # To ensure a specific config for the tests
33 systemd.tmpfiles.rules =
34 let
35 testConfig = (pkgs.formats.yaml { }).generate "miracle-wm.yaml" {
36 terminal = "env WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty";
37 startup_apps = [
38 {
39 command = "foot";
40 restart_on_death = false;
41 }
42 ];
43 };
44 in
45 [
46 "d ${config.users.users.alice.home}/.config 0700 alice users - -"
47 "L ${config.users.users.alice.home}/.config/miracle-wm.yaml - - - - ${testConfig}"
48 ];
49
50 environment = {
51 shellAliases = {
52 test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
53 test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
54 };
55
56 systemPackages = with pkgs; [
57 mesa-demos
58 wayland-utils
59 foot
60 alacritty
61 ];
62
63 # To help with OCR
64 etc."xdg/foot/foot.ini".source = (pkgs.formats.ini { }).generate "foot.ini" {
65 main = {
66 font = "inconsolata:size=16";
67 };
68 colors = rec {
69 foreground = "000000";
70 background = "ffffff";
71 regular2 = foreground;
72 };
73 };
74 etc."xdg/alacritty/alacritty.toml".source = (pkgs.formats.toml { }).generate "alacritty.toml" {
75 font = rec {
76 normal.family = "Inconsolata";
77 bold.family = normal.family;
78 italic.family = normal.family;
79 bold_italic.family = normal.family;
80 size = 16;
81 };
82 colors = rec {
83 primary = {
84 foreground = "0x000000";
85 background = "0xffffff";
86 };
87 normal = {
88 green = primary.foreground;
89 };
90 };
91 };
92 };
93
94 fonts.packages = [ pkgs.inconsolata ];
95 };
96
97 enableOCR = true;
98
99 testScript =
100 { ... }:
101 ''
102 start_all()
103 machine.wait_for_unit("multi-user.target")
104
105 # Wait for Miriway to complete startup
106 machine.wait_for_file("/run/user/1000/wayland-0")
107 machine.succeed("pgrep miracle-wm")
108 machine.screenshot("miracle-wm_launched")
109
110 # Test Wayland
111 with subtest("wayland client works"):
112 # We let miracle-wm start the first terminal, as we might get stuck if it's not ready to process the first keybind
113 # machine.send_key("ctrl-alt-t")
114 machine.wait_for_text("alice@machine")
115 machine.send_chars("test-wayland\n")
116 machine.wait_for_file("/tmp/test-wayland-exit-ok")
117 machine.copy_from_vm("/tmp/test-wayland.out")
118 machine.screenshot("foot_wayland_info")
119
120 # please actually register that we want to close the window
121 machine.succeed("ydotool mousemove -- 10 10")
122 machine.sleep(3)
123
124 machine.send_chars("exit\n")
125
126 # please actually register that we want to close the window
127 machine.succeed("ydotool mousemove -- 10 10")
128 machine.sleep(3)
129
130 machine.wait_until_fails("pgrep foot")
131
132 # Test XWayland
133 with subtest("x11 client works"):
134 machine.send_key("meta_l-ret")
135 machine.wait_for_text("alice@machine")
136 machine.send_chars("test-x11\n")
137 machine.wait_for_file("/tmp/test-x11-exit-ok")
138 machine.copy_from_vm("/tmp/test-x11.out")
139 machine.screenshot("alacritty_glinfo")
140
141 # please actually register that we want to close the window
142 machine.succeed("ydotool mousemove -- 10 10")
143 machine.sleep(3)
144
145 machine.send_chars("exit\n")
146
147 # please actually register that we want to close the window
148 machine.succeed("ydotool mousemove -- 10 10")
149 machine.sleep(3)
150
151 machine.wait_until_fails("pgrep alacritty")
152 '';
153}