Files
HermenixandClaude Opus 5 a37b3dd485 checks: give both VM machines a virtio GPU, and say why when it is not enough
`nix build .#checks.x86_64-linux.vm-basic` failed because Hyprland 0.56.2
aborted with `CBackend::create() failed!` on every start. Reading aquamarine
0.15.1 rather than guessing at it, that abort had three independent causes on a
NixOS test machine, and none of them is visible in the journal until
`debug:disable_logs = false` is set -- Hyprland mutes aquamarine, so the abort
is all that survives. checks/lib/gpu-session.nix now supplies all three and
records the evidence for each:

  * `-vga virtio`, for a DRM render node. `virtualisation.graphics = false`
    still leaves QEMU's default bochs-drm adapter, which gives card0 and no
    renderD*. Measured in the guest: `-vga virtio` -> card0 + renderD128;
    `-device virtio-gpu-pci` only *adds* a card next to bochs-drm, so it would
    need `-vga none` beside it.

  * `hardware.graphics.enable`, so Mesa's GBM backends exist at all. Without it
    gbm_create_device() fails with "MESA-LOADER: failed to open dri:
    /run/opengl-driver/lib/gbm/dri_gbm.so" and aquamarine reports "Cannot open
    backend: no allocator available".

  * `SEATD_VTBOUND=0`, so libseat's embedded seatd hands out a seat with no VT.
    `CHeadlessBackend::drmFD()` returns -1 unconditionally, so the *only*
    source of an allocator is the DRM backend, which opens /dev/dri/card0
    through libseat -- and the default VT-bound seat needs /dev/tty0, which the
    unprivileged service user cannot open.

The diagnostics dump grows a "graphics devices" section (`ls -l /dev/dri`,
`cat /proc/fb`) and a "wayland socket vs WAYLAND_DISPLAY" section, so the next
machine that is missing a render node, or that binds a socket the frame server
is not waiting on, says so in three lines instead of timing out mutely.
vm-basic's `dump()` is now vm-hyprland's, which reports the exit status too.

vm-basic also gained `python3` in the guest: its last subtest shells out to a
python one-liner and had been dying on exit code 127 -- invisible until the
compositor got far enough to reach that subtest.

Neither check passes yet, and the two remaining blockers both live in
nix/module.nix, which this slice may not edit, so they are reported rather
than patched:

  * vm-basic stops at "the module's two units come up". The compositor is up
    and healthy; the frame server sits in ExecStartPre forever. The module
    hardcodes `waylandDisplay = "wayland-0"`, but Hyprland's socket loop is
    `// get socket, avoid using 0` over candidates 1..32 (src/Compositor.cpp),
    so the session binds wayland-1. Forcing WAYLAND_DISPLAY=wayland-1 in the
    guest was verified to carry vm-basic through every other subtest.

  * vm-hyprland stops at "the compositor reports the configured headless
    output" with "hyprctl never reported a HEADLESS-1 monitor". hyprctl reports
    `Monitor Virtual-1` at 1280x800 -- the virtio-gpu output. A HEADLESS-N
    output only exists after `hyprctl output create headless`, which the module
    never issues; Hyprland's own fallback output is named FALLBACK. The
    `monitor = HEADLESS-1, ...` line in hyprland.conf is a rule for a monitor
    that is never created.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018fJZYyS4pqxt2FC37JsFYd
2026-09-28 12:28:01 +00:00

158 lines
5.5 KiB
Nix

# checks.<system>.vm-basic -- boot a real machine with the module enabled, point
# `captureCommand` at a fake capture program, and read the socket.
#
# This check is about the module's wiring and the wire contract, not about
# Hyprland: the fake capture emits one fixed PNG, so "two frames arrived and
# they are the same image" is a real assertion rather than a coincidence.
{
testers,
hhstream,
testTools,
python3,
hhsModule,
width ? 1280,
height ? 720,
fps ? 30,
socketPath ? "/run/hyprland-headless-stream/stream.sock",
}:
testers.runNixOSTest {
name = "hhstream-vm-basic";
# KVM is available, so this is a minute or two; cap it so a hang is a failure
# rather than a wedged builder.
globalTimeout = 900;
nodes.machine = {
# gpu-session.nix is what makes the compositor able to start at all; see
# that file for the three things a bare test machine is missing.
imports = [ hhsModule ./lib/gpu-session.nix ];
services.hyprland-headless-stream = {
enable = true;
# The module declares `package` with no default (see README.dev.md), so the
# test has to supply the flake's build.
package = hhstream;
inherit socketPath;
frameRate = fps;
format = "png";
outputs = [
{
name = "HEADLESS-1";
inherit width height;
refresh = fps;
}
];
captureCommand = [
"${testTools}/bin/hhs-fake-capture"
"--width"
(toString width)
"--height"
(toString height)
];
};
environment.systemPackages = [
testTools
hhstream
# The "client dying mid-stream" subtest opens the socket from a python
# one-liner in the guest. hhstream's own interpreter is reachable only
# through its wrapper, so without this the subtest dies on exit code 127
# (`python3: command not found`) rather than on anything it asserts.
python3
];
# Mesa and the compositor together need more than the fake capture alone
# did; the GPU itself comes from gpu-session.nix.
virtualisation = {
memorySize = 2048;
cores = 2;
diskSize = 4096;
graphics = false;
};
};
testScript = ''
SOCKET = "${socketPath}"
ASSERT = "hhs-assert-stream --socket " + SOCKET
def dump(label):
print(f"########## diagnostics: {label} ##########")
status, out = machine.execute("hhs-hyprland-diagnostics", timeout=120)
print(out)
print(f"########## end diagnostics (exit {status}) ##########")
start_all()
with subtest("the module's two units come up"):
try:
machine.wait_for_unit("hyprland-headless.service", timeout=120)
machine.wait_for_unit("hyprland-headless-stream.service", timeout=120)
except Exception:
dump("units did not start")
raise
with subtest("the socket exists, owned by the service user, mode 0660"):
try:
machine.wait_for_file(SOCKET, timeout=60)
print(machine.succeed(f"stat -c 'owner=%U group=%G mode=%a type=%F' {SOCKET}"))
machine.succeed(f"[ \"$(stat -c %a {SOCKET})\" = 660 ]")
machine.succeed(f"[ \"$(stat -c %U {SOCKET})\" = hhstream ]")
machine.succeed(f"[ \"$(stat -c %G {SOCKET})\" = hhstream ]")
machine.succeed(f"[ \"$(stat -c %F {SOCKET})\" = socket ]")
except Exception:
dump("socket missing or wrong ownership")
raise
with subtest("the Hello parses, magic is HHS1, size is non-zero"):
try:
print(machine.succeed(f"{ASSERT} --frames 1 --timeout 30"))
except Exception:
dump("Hello did not parse")
raise
with subtest("two frames arrive, non-empty, byte-identical, matching the Hello"):
try:
print(
machine.succeed(
f"{ASSERT} --frames 2 --timeout 60"
" --expect-width ${toString width} --expect-height ${toString height}"
" --expect-format image/png --expect-fps ${toString fps}"
" --require-png --identical-frames --min-bytes 1"
)
)
except Exception:
dump("frames did not satisfy the contract")
raise
with subtest("two clients are served concurrently and independently"):
try:
print(
machine.succeed(
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/a.log 2>&1 & p1=$!; "
f"{ASSERT} --frames 3 --timeout 60 --require-png > /tmp/b.log 2>&1 & p2=$!; "
"wait $p1; r1=$?; wait $p2; r2=$?; "
"echo '--- client a ---'; cat /tmp/a.log; "
"echo '--- client b ---'; cat /tmp/b.log; "
"exit $((r1 + r2))"
)
)
except Exception:
dump("concurrent clients were not both served")
raise
with subtest("a client dying mid-stream leaves the server serving"):
try:
machine.succeed(
"timeout 5 python3 -c 'import socket;"
f"s=socket.socket(socket.AF_UNIX);s.connect(\"{SOCKET}\");s.recv(1);s.close()'"
)
print(machine.succeed(f"{ASSERT} --frames 2 --timeout 60 --require-png"))
machine.succeed("systemctl is-active hyprland-headless-stream.service")
except Exception:
dump("server did not survive a client dying mid-frame")
raise
'';
}