summaryrefslogtreecommitdiffstats
path: root/nixos/tests/seatd.nix
blob: f8a88a1cb9efde40eb291eabd445da9eb59055c7 (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
{ pkgs, lib, ... }:

let
  seatd-test = pkgs.writeShellApplication {
    name = "seatd-client-pid";
    text = ''
      journalctl -u seatd --no-pager -b | while read -r line; do
          case "$line" in
          *"New client connected"*)
              line="''${line##*pid: }"
              pid="''${line%%,*}"
              ;;
          *"Opened client"*)
              echo "$pid"
              exit
          esac
      done;
    '';
  };
in
{
  name = "seatd";
  meta.maintainers = with lib.maintainers; [ sinanmohd ];

  nodes.machine =
    { ... }:
    {
      imports = [ ./common/user-account.nix ];
      services.getty.autologinUser = "alice";
      users.users.alice.extraGroups = [
        "seat"
        "wheel"
      ];

      fonts.enableDefaultPackages = true;
      environment.systemPackages = with pkgs; [
        dwl
        foot
        seatd-test
      ];

      programs.bash.loginShellInit = ''
        [ "$(tty)" = "/dev/tty1" ] &&
            dwl -s 'foot touch /tmp/foot_started'
      '';

      hardware.graphics.enable = true;
      virtualisation.qemu.options = [ "-vga none -device virtio-gpu-pci" ];
      services.seatd.enable = true;
    };

  testScript = ''
    machine.wait_for_unit("seatd.service")
    machine.wait_for_file("/tmp/foot_started")
    machine.succeed("test $(seatd-client-pid) = $(pgrep dwl)")
  '';
}