@@ -0,0 +1,92 @@
1+import ./make-test-python.nix ({ pkgs, lib, ...} :
2+
3+{
4+ name = "sway";
5+ meta = {
6+ maintainers = with lib.maintainers; [ primeos synthetica ];
7+ };
8+
9+ machine = { config, ... }: {
10+ # Automatically login on tty1 as a normal user:
11+ imports = [ ./common/user-account.nix ];
12+ services.getty.autologinUser = "alice";
13+
14+ environment = {
15+ # For glinfo and wayland-info:
16+ systemPackages = with pkgs; [ mesa-demos wayland-utils ];
17+ # Use a fixed SWAYSOCK path (for swaymsg):
18+ variables."SWAYSOCK" = "/tmp/sway-ipc.sock";
19+ # For convenience:
20+ shellAliases = {
21+ test-x11 = "glinfo | head -n 3 | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
22+ test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
23+ };
24+ };
25+
26+ # Automatically configure and start Sway when logging in on tty1:
27+ programs.bash.loginShellInit = ''
28+ if [ "$(tty)" = "/dev/tty1" ]; then
29+ set -e
30+
31+ mkdir -p ~/.config/sway
32+ sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
33+
34+ sway --validate
35+ sway && touch /tmp/sway-exit-ok
36+ fi
37+ '';
38+
39+ programs.sway.enable = true;
40+
41+ virtualisation.memorySize = 1024;
42+ # Need to switch to a different VGA card / GPU driver than the default one (std) so that Sway can launch:
43+ virtualisation.qemu.options = [ "-vga virtio" ];
44+ };
45+
46+ enableOCR = true;
47+
48+ testScript = { nodes, ... }: ''
49+ start_all()
50+ machine.wait_for_unit("multi-user.target")
51+
52+ # To check the version:
53+ print(machine.succeed("sway --version"))
54+
55+ # Wait for Sway to complete startup:
56+ machine.wait_for_file("/run/user/1000/wayland-1")
57+ machine.wait_for_file("/tmp/sway-ipc.sock")
58+
59+ # Test XWayland:
60+ machine.succeed(
61+ "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
62+ )
63+ machine.wait_for_text("alice@machine")
64+ machine.send_chars("test-x11\n")
65+ machine.wait_for_file("/tmp/test-x11-exit-ok")
66+ print(machine.succeed("cat /tmp/test-x11.out"))
67+ machine.screenshot("alacritty_glinfo")
68+ machine.succeed("pkill alacritty")
69+
70+ # Start a terminal (Alacritty) on workspace 3:
71+ machine.send_key("alt-3")
72+ machine.succeed(
73+ "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=wayland DISPLAY=invalid alacritty'"
74+ )
75+ machine.wait_for_text("alice@machine")
76+ machine.send_chars("test-wayland\n")
77+ machine.wait_for_file("/tmp/test-wayland-exit-ok")
78+ print(machine.succeed("cat /tmp/test-wayland.out"))
79+ machine.screenshot("alacritty_wayland_info")
80+ machine.send_key("alt-shift-q")
81+ machine.wait_until_fails("pgrep alacritty")
82+
83+ # Test swaynag:
84+ machine.send_key("alt-shift-e")
85+ machine.wait_for_text("You pressed the exit shortcut.")
86+ machine.screenshot("sway_exit")
87+
88+ # Exit Sway and verify process exit status 0:
89+ machine.succeed("su - alice -c 'swaymsg exit || true'")
90+ machine.wait_for_file("/tmp/sway-exit-ok")
91+ '';
92+})