Release NixOS 23.11
[NixPkgs.git] / nixos / tests / gnome-xorg.nix
blob6ca700edcac38457c93d69eb4e2ffce81bc281b8
1 import ./make-test-python.nix ({ pkgs, lib, ...} : {
2   name = "gnome-xorg";
3   meta = {
4     maintainers = lib.teams.gnome.members;
5   };
7   nodes.machine = { nodes, ... }: let
8     user = nodes.machine.users.users.alice;
9   in
11     { imports = [ ./common/user-account.nix ];
13       services.xserver.enable = true;
15       services.xserver.displayManager = {
16         gdm.enable = true;
17         gdm.debug = true;
18         autoLogin = {
19           enable = true;
20           user = user.name;
21         };
22       };
24       services.xserver.desktopManager.gnome.enable = true;
25       services.xserver.desktopManager.gnome.debug = true;
26       services.xserver.displayManager.defaultSession = "gnome-xorg";
28       systemd.user.services = {
29         "org.gnome.Shell@x11" = {
30           serviceConfig = {
31             ExecStart = [
32               # Clear the list before overriding it.
33               ""
34               # Eval API is now internal so Shell needs to run in unsafe mode.
35               # TODO: improve test driver so that it supports openqa-like manipulation
36               # that would allow us to drop this mess.
37               "${pkgs.gnome.gnome-shell}/bin/gnome-shell --unsafe-mode"
38             ];
39           };
40         };
41       };
43     };
45   testScript = { nodes, ... }: let
46     user = nodes.machine.users.users.alice;
47     uid = toString user.uid;
48     bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus";
49     xauthority = "/run/user/${uid}/gdm/Xauthority";
50     display = "DISPLAY=:0.0";
51     env = "${bus} XAUTHORITY=${xauthority} ${display}";
52     # Run a command in the appropriate user environment
53     run = command: "su - ${user.name} -c '${bus} ${command}'";
55     # Call javascript in gnome shell, returns a tuple (success, output), where
56     # `success` is true if the dbus call was successful and output is what the
57     # javascript evaluates to.
58     eval = command: run "gdbus call --session -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval ${command}";
60     # False when startup is done
61     startingUp = eval "Main.layoutManager._startingUp";
63     # Start Console
64     launchConsole = run "gapplication launch org.gnome.Console";
66     # Hopefully Console's wm class
67     wmClass = eval "global.display.focus_window.wm_class";
68   in ''
69       with subtest("Login to GNOME Xorg with GDM"):
70           machine.wait_for_x()
71           # Wait for alice to be logged in"
72           machine.wait_for_unit("default.target", "${user.name}")
73           machine.wait_for_file("${xauthority}")
74           machine.succeed("xauth merge ${xauthority}")
75           # Check that logging in has given the user ownership of devices
76           assert "alice" in machine.succeed("getfacl -p /dev/snd/timer")
78       with subtest("Wait for GNOME Shell"):
79           # correct output should be (true, 'false')
80           machine.wait_until_succeeds(
81               "${startingUp} | grep -q 'true,..false'"
82           )
84       with subtest("Open Console"):
85           # Close the Activities view so that Shell can correctly track the focused window.
86           machine.send_key("esc")
88           machine.succeed(
89               "${launchConsole}"
90           )
91           # correct output should be (true, '"kgx"')
92           # For some reason, this deviates from Wayland.
93           machine.wait_until_succeeds(
94               "${wmClass} | grep -q  'true,...kgx'"
95           )
96           machine.sleep(20)
97           machine.screenshot("screen")
98     '';