summaryrefslogtreecommitdiffstats
path: root/nixos/tests/qtile/default.nix
blob: 7c51754d550e177f807e2dd770e19c7b1fba4af7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ lib, ... }:
{
  name = "qtile";

  meta = {
    maintainers = with lib.maintainers; [
      sigmanificient
      gurjaka
    ];
  };

  nodes.machine =
    {
      pkgs,
      lib,
      ...
    }:
    let
      # We create a custom Qtile configuration file that adds a
      # startup hook to qtile. This ensure we can reproducibly check
      # when Qtile is truly ready to receive our inputs
      config-deriv = pkgs.callPackage ./config.nix { };
    in
    {
      imports = [
        ../common/x11.nix
        ../common/user-account.nix
      ];
      test-support.displayManager.auto.user = "alice";

      services.xserver.windowManager.qtile = {
        enable = true;
        configFile = "${config-deriv}/config.py";
      };

      services.displayManager.defaultSession = lib.mkForce "qtile";

      environment.systemPackages = [
        pkgs.kitty
        pkgs.xwininfo
      ];
    };

  testScript = ''
    from pathlib import Path

    with subtest("ensure x starts"):
        machine.wait_for_x()
        machine.wait_for_file("/home/alice/.Xauthority")
        machine.succeed("xauth merge ~alice/.Xauthority")

    with subtest("ensure client is available"):
        machine.succeed("qtile --version")

    with subtest("Qtile signals that it is ready"):
        qtile_logfile = Path("/home/alice/.local/share/qtile/qtile.log")

        machine.succeed(f"mkdir -p {qtile_logfile.parent}")
        machine.succeed(f"touch {qtile_logfile}")
        machine.succeed(f"sh -c 'tail -f {qtile_logfile} | grep --line-buffered \'ready\' -m 1'")

    with subtest("ensure we can open a new terminal"):
        machine.send_key("meta_l-ret")
        machine.wait_for_window(r"alice.*?machine")
        machine.screenshot("terminal")
  '';
}