summary refs log tree commit diff
path: root/release/checks/wayland/default.nix
blob: 9c18d1881d730dd1e6e304b86c08c7c5b9f45534 (plain) (blame)
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
68
69
70
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2023 Alyssa Ross <hi@alyssa.is>

import ../../../lib/eval-config.nix ({ config, ... }:

let
  inherit (import ../../../host/rootfs { inherit config; }) appvm;
  run = import ../../../vm/app/hello-wayland.nix { inherit config; };
  surface-notify = import ./surface-notify { inherit config; };
in

config.pkgs.nixosTest ({ pkgs, ... }: {
  name = "spectrum-wayland";

  nodes.machine = { ... }: {
    hardware.opengl.enable = true;

    systemd.services.crosvm = {
      after = [ "crosvm-gpu.service" "weston.service" ];
      requires = [ "crosvm-gpu.service" "weston.service" ];
      serviceConfig.ExecStart = "${pkgs.crosvm}/bin/crosvm run --disk ${appvm}/img/appvm/blk/root.img --disk ${run}/blk/run.img -p \"console=ttyS0 root=PARTLABEL=root\" --vhost-user-gpu /run/crosvm-gpu.sock --serial type=stdout,hardware=virtio-console,stdin=true ${appvm}/img/appvm/vmlinux";
    };

    systemd.services.crosvm-gpu = {
      requires = [ "weston.service" ];
      script = ''
        rm -f /run/crosvm-gpu.sock
        (
            while ! [ -S /run/crosvm-gpu.sock ]; do
                sleep .1
            done
            systemd-notify --ready --no-block
        ) &
        exec ${pkgs.crosvm}/bin/crosvm device gpu \
            --socket /run/crosvm-gpu.sock \
            --wayland-sock /run/wayland-1 \
            --params '{"context-types":"cross-domain"}'
      '';
      serviceConfig.NotifyAccess = "all";
      serviceConfig.Type = "notify";
    };

    systemd.services.surface-notify-socket = {
      serviceConfig.ExecStart = "${pkgs.coreutils}/bin/mkfifo /run/surface-notify";
      serviceConfig.RemainAfterExit = true;
      serviceConfig.Type = "oneshot";
    };

    systemd.services.weston = {
      after = [ "surface-notify-socket.service" ];
      requires = [ "surface-notify-socket.service" ];
      environment.XDG_RUNTIME_DIR = "/run";
      environment.WAYLAND_DEBUG = "server";
      serviceConfig.ExecStart = "${pkgs.westonLite}/bin/weston --modules ${surface-notify}/lib/weston/surface-notify.so,systemd-notify.so";
      serviceConfig.TTYPath = "/dev/tty7";
      serviceConfig.Type = "notify";
    };
  };

  testScript = { ... }: ''
    machine.wait_for_unit('multi-user.target')

    machine.start_job('crosvm.service')

    machine.wait_for_unit('surface-notify-socket.service');
    machine.succeed('test "$(wc -c /run/surface-notify)" = "1 /run/surface-notify"', timeout=180)

    machine.screenshot('weston')
  '';
}))