1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
4 maintainers = with lib.maintainers; [ primeos synthetica ];
7 # testScriptWithTypes:49: error: Cannot call function of unknown type
8 # (machine.succeed if succeed else machine.execute)(
10 # Found 1 error in 1 file (checked 1 source file)
13 nodes.machine = { config, ... }: {
14 # Automatically login on tty1 as a normal user:
15 imports = [ ./common/user-account.nix ];
16 services.getty.autologinUser = "alice";
19 # For glinfo and wayland-info:
20 systemPackages = with pkgs; [ mesa-demos wayland-utils alacritty ];
21 # Use a fixed SWAYSOCK path (for swaymsg):
23 "SWAYSOCK" = "/tmp/sway-ipc.sock";
24 # TODO: Investigate if we can get hardware acceleration to work (via
25 # virtio-gpu and Virgil). We currently have to use the Pixman software
26 # renderer since the GLES2 renderer doesn't work inside the VM (even
27 # with WLR_RENDERER_ALLOW_SOFTWARE):
28 # "WLR_RENDERER_ALLOW_SOFTWARE" = "1";
29 "WLR_RENDERER" = "pixman";
33 test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
34 test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
38 etc."xdg/foot/foot.ini".text = lib.generators.toINI { } {
40 font = "inconsolata:size=14";
43 foreground = "000000";
44 background = "ffffff";
45 regular2 = foreground;
50 fonts.fonts = [ pkgs.inconsolata ];
52 # Automatically configure and start Sway when logging in on tty1:
53 programs.bash.loginShellInit = ''
54 if [ "$(tty)" = "/dev/tty1" ]; then
57 mkdir -p ~/.config/sway
58 sed s/Mod4/Mod1/ /etc/sway/config > ~/.config/sway/config
61 sway && touch /tmp/sway-exit-ok
65 programs.sway.enable = true;
67 # To test pinentry via gpg-agent:
68 programs.gnupg.agent.enable = true;
70 # Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
71 virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
76 testScript = { nodes, ... }: ''
79 def swaymsg(command: str, succeed=True):
80 with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)):
81 (machine.succeed if succeed else machine.execute)(
82 f"su - alice -c {shlex.quote('swaymsg -- ' + command)}"
86 machine.wait_for_unit("multi-user.target")
88 # To check the version:
89 print(machine.succeed("sway --version"))
91 # Wait for Sway to complete startup:
92 machine.wait_for_file("/run/user/1000/wayland-1")
93 machine.wait_for_file("/tmp/sway-ipc.sock")
95 # Test XWayland (foot does not support X):
96 swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty")
97 machine.wait_for_text("alice@machine")
98 machine.send_chars("test-x11\n")
99 machine.wait_for_file("/tmp/test-x11-exit-ok")
100 print(machine.succeed("cat /tmp/test-x11.out"))
101 machine.copy_from_vm("/tmp/test-x11.out")
102 machine.screenshot("alacritty_glinfo")
103 machine.succeed("pkill alacritty")
105 # Start a terminal (foot) on workspace 3:
106 machine.send_key("alt-3")
108 machine.send_key("alt-ret")
109 machine.wait_for_text("alice@machine")
110 machine.send_chars("test-wayland\n")
111 machine.wait_for_file("/tmp/test-wayland-exit-ok")
112 print(machine.succeed("cat /tmp/test-wayland.out"))
113 machine.copy_from_vm("/tmp/test-wayland.out")
114 machine.screenshot("foot_wayland_info")
115 machine.send_key("alt-shift-q")
116 machine.wait_until_fails("pgrep foot")
118 # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
119 # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
120 swaymsg("exec gpg --no-tty --yes --quick-generate-key test")
121 machine.wait_until_succeeds("pgrep --exact gpg")
122 machine.wait_for_text("Passphrase")
123 machine.screenshot("gpg_pinentry")
124 machine.send_key("alt-shift-q")
125 machine.wait_until_fails("pgrep --exact gpg")
128 machine.send_key("alt-shift-e")
129 machine.wait_for_text("You pressed the exit shortcut.")
130 machine.screenshot("sway_exit")
132 swaymsg("exec swaylock")
133 machine.wait_until_succeeds("pgrep -x swaylock")
135 machine.send_chars("${nodes.machine.config.users.users.alice.password}")
136 machine.send_key("ret")
137 machine.wait_until_fails("pgrep -x swaylock")
139 # Exit Sway and verify process exit status 0:
140 swaymsg("exit", succeed=False)
141 machine.wait_until_fails("pgrep -x sway")
142 machine.wait_for_file("/tmp/sway-exit-ok")