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."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 # To test pinentry via gpg-agent:
42 programs.gnupg.agent.enable = true;
43
44 virtualisation.memorySize = 1024;
45 # Need to switch to a different VGA card / GPU driver than the default one (std) so that Sway can launch:
46 virtualisation.qemu.options = [ "-vga virtio" ];
47 };
48
49 enableOCR = true;
50
51 testScript = { nodes, ... }: ''
52 start_all()
53 machine.wait_for_unit("multi-user.target")
54
55 # To check the version:
56 print(machine.succeed("sway --version"))
57
58 # Wait for Sway to complete startup:
59 machine.wait_for_file("/run/user/1000/wayland-1")
60 machine.wait_for_file("/tmp/sway-ipc.sock")
61
62 # Test XWayland:
63 machine.succeed(
64 "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
65 )
66 machine.wait_for_text("alice@machine")
67 machine.send_chars("test-x11\n")
68 machine.wait_for_file("/tmp/test-x11-exit-ok")
69 print(machine.succeed("cat /tmp/test-x11.out"))
70 machine.screenshot("alacritty_glinfo")
71 machine.succeed("pkill alacritty")
72
73 # Start a terminal (Alacritty) on workspace 3:
74 machine.send_key("alt-3")
75 machine.succeed(
76 "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=wayland DISPLAY=invalid alacritty'"
77 )
78 machine.wait_for_text("alice@machine")
79 machine.send_chars("test-wayland\n")
80 machine.wait_for_file("/tmp/test-wayland-exit-ok")
81 print(machine.succeed("cat /tmp/test-wayland.out"))
82 machine.screenshot("alacritty_wayland_info")
83 machine.send_key("alt-shift-q")
84 machine.wait_until_fails("pgrep alacritty")
85
86 # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
87 # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
88 machine.succeed(
89 "su - alice -c 'swaymsg -- exec gpg --no-tty --yes --quick-generate-key test'"
90 )
91 machine.wait_until_succeeds("pgrep --exact gpg")
92 machine.wait_for_text("Passphrase")
93 machine.screenshot("gpg_pinentry")
94 machine.send_key("alt-shift-q")
95 machine.wait_until_fails("pgrep --exact gpg")
96
97 # Test swaynag:
98 machine.send_key("alt-shift-e")
99 machine.wait_for_text("You pressed the exit shortcut.")
100 machine.screenshot("sway_exit")
101
102 # Exit Sway and verify process exit status 0:
103 machine.succeed("su - alice -c 'swaymsg exit || true'")
104 machine.wait_for_file("/tmp/sway-exit-ok")
105 '';
106})