1import ./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 = {
19 "SWAYSOCK" = "/tmp/sway-ipc.sock";
20 "WLR_RENDERER_ALLOW_SOFTWARE" = "1";
21 };
22 # For convenience:
23 shellAliases = {
24 test-x11 = "glinfo | head -n 3 | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
25 test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
26 };
27 };
28
29 # Automatically configure and start Sway when logging in on tty1:
30 programs.bash.loginShellInit = ''
31 if [ "$(tty)" = "/dev/tty1" ]; then
32 set -e
33
34 mkdir -p ~/.config/sway
35 sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
36
37 sway --validate
38 sway && touch /tmp/sway-exit-ok
39 fi
40 '';
41
42 programs.sway.enable = true;
43
44 # To test pinentry via gpg-agent:
45 programs.gnupg.agent.enable = true;
46
47 # Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
48 virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
49 };
50
51 enableOCR = true;
52
53 testScript = { nodes, ... }: ''
54 start_all()
55 machine.wait_for_unit("multi-user.target")
56
57 # To check the version:
58 print(machine.succeed("sway --version"))
59
60 # Wait for Sway to complete startup:
61 machine.wait_for_file("/run/user/1000/wayland-1")
62 machine.wait_for_file("/tmp/sway-ipc.sock")
63
64 # Test XWayland:
65 machine.succeed(
66 "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
67 )
68 machine.wait_for_text("alice@machine")
69 machine.send_chars("test-x11\n")
70 machine.wait_for_file("/tmp/test-x11-exit-ok")
71 print(machine.succeed("cat /tmp/test-x11.out"))
72 machine.screenshot("alacritty_glinfo")
73 machine.succeed("pkill alacritty")
74
75 # Start a terminal (Alacritty) on workspace 3:
76 machine.send_key("alt-3")
77 machine.succeed(
78 "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=wayland DISPLAY=invalid alacritty'"
79 )
80 machine.wait_for_text("alice@machine")
81 machine.send_chars("test-wayland\n")
82 machine.wait_for_file("/tmp/test-wayland-exit-ok")
83 print(machine.succeed("cat /tmp/test-wayland.out"))
84 machine.screenshot("alacritty_wayland_info")
85 machine.send_key("alt-shift-q")
86 machine.wait_until_fails("pgrep alacritty")
87
88 # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
89 # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
90 machine.succeed(
91 "su - alice -c 'swaymsg -- exec gpg --no-tty --yes --quick-generate-key test'"
92 )
93 machine.wait_until_succeeds("pgrep --exact gpg")
94 machine.wait_for_text("Passphrase")
95 machine.screenshot("gpg_pinentry")
96 machine.send_key("alt-shift-q")
97 machine.wait_until_fails("pgrep --exact gpg")
98
99 # Test swaynag:
100 machine.send_key("alt-shift-e")
101 machine.wait_for_text("You pressed the exit shortcut.")
102 machine.screenshot("sway_exit")
103
104 # Exit Sway and verify process exit status 0:
105 machine.succeed("su - alice -c 'swaymsg exit || true'")
106 machine.wait_until_fails("pgrep -x sway")
107
108 # TODO: Sway currently segfaults after "swaymsg exit" but only in this VM test:
109 # machine # [ 104.090032] sway[921]: segfault at 3f800008 ip 00007f7dbdc25f10 sp 00007ffe282182f8 error 4 in libwayland-server.so.0.1.0[7f7dbdc1f000+8000]
110 # machine.wait_for_file("/tmp/sway-exit-ok")
111 '';
112})