Files
HermenixandClaude Opus 5 6510e315d4 module: make outputs monitor rules for real connectors, and own the seat flag
A machine running this module has a GPU. aquamarine's headless backend has
no allocator of its own -- `CHeadlessBackend::drmFD()` returns -1 and
`CBackend::start()` takes the allocator from the first backend with a drm fd
-- so the session always rides on the DRM backend and always has the host's
own connectors. `HEADLESS-1` is a name no connector will ever have, which
made the shipped default a monitor rule Hyprland silently ignored, and made
`vm-hyprland`'s assertion on that name unsatisfiable.

`outputs` now means "monitor rules applied to whatever outputs the machine
has". `name` is a regex against the real connector names and defaults to the
empty string -- Hyprland's own wildcard form, as in its shipped
`monitor=,preferred,auto,1` -- so `enable = true` alone gives a session at a
known size on any host. Nothing else about the option changed.

SEATD_VTBOUND=0 moves from checks/lib/gpu-session.nix into the compositor
unit, where it belongs: libseat finds no seatd socket and no logind session
for a system service, falls back to its embedded seatd, and that seat is
VT-bound by default -- so it opens /dev/tty0, which the service user cannot,
and every device open is refused. That is true on any host, not just in the
test. gpu-session.nix keeps only the two things that really are the test
machine's business: a render node and Mesa.

vm-hyprland now asserts over `hyprctl -j monitors` that at least one monitor
exists at the configured mode, with no monitor name anywhere in the check.
It also gains a wallpaper, because `--reject-blank` could not otherwise mean
anything: the session the module configures by default is a flat black
field, which grim captures as an all-zero 1280x720 RGBA PNG of exactly 3653
bytes -- `blank_png_size()` to the byte. Runs that passed that assertion were
reading Hyprland's startup notification overlay, which expires after about
fifteen seconds. With `misc:force_default_wallpaper` on, the frame is 85267
bytes with all 921600 pixels non-zero and is byte-identical at +15s, +30s and
+60s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M5GEju6XhoRXDWvEiaAX2r
2026-09-28 21:51:24 +00:00

236 lines
9.5 KiB
Nix

# checks.<system>.vm-hyprland -- the real one. Same machine as vm-basic, but no
# `captureCommand` override, so the server captures the actual headless
# compositor through grim.
#
# This is the check expected to be flaky, so it is deliberately impatient: every
# wait has a bounded timeout, no assertion is retried, and any failure dumps the
# compositor's log and `hyprctl monitors` before it propagates. A flake you can
# read is worth more than a flake that eventually goes green.
#
# There is exactly one waiting loop, and it waits for the compositor to finish
# starting (see "the session settles ..." below) rather than for an assertion to
# pass. Every assertion after it runs once.
{
testers,
hhstream,
testTools,
hhsModule,
hyprland,
grim,
width ? 1280,
height ? 720,
fps ? 30,
socketPath ? "/run/hyprland-headless-stream/stream.sock",
}:
testers.runNixOSTest {
name = "hhstream-vm-hyprland";
globalTimeout = 1800;
nodes.machine = {
# gpu-session.nix is what makes the compositor able to start at all; see
# that file for the two pieces of hardware a bare test machine is missing
# (the third thing it used to carry, SEATD_VTBOUND=0, is in nix/module.nix
# now -- it is a property of the session, not of the test machine).
imports = [ hhsModule ./lib/gpu-session.nix ];
services.hyprland-headless-stream = {
enable = true;
package = hhstream;
hyprlandPackage = hyprland;
inherit socketPath;
frameRate = fps;
format = "png";
# No `name`, so the module's wildcard rule applies to whatever connector
# the virtio GPU gives this guest. The check must not know that name: on
# QEMU it is `Virtual-1`, on a real host it is whatever the DRM backend
# reports, and a rule naming a connector that does not exist is silently
# ignored rather than an error.
outputs = [
{
inherit width height;
refresh = fps;
}
];
# No captureCommand: the module's default (grim) is the point of this check.
# Put a picture on the screen, so that `--reject-blank` below is an
# assertion and not a formality.
#
# The session the module configures by default is a flat field: no logo,
# no splash, no wallpaper, `background_color = 0x000000`. Measured in this
# guest, grim captures that as 1280x720 RGBA in which every byte is zero,
# encoding to *exactly* 3653 bytes -- which is `blank_png_size()` in
# tests/assert_stream.py to the byte. A flat field is by construction
# indistinguishable from a zero-filled buffer, so against the default
# config `--reject-blank` cannot pass, and any run in which it appears to
# is reading something transient (the startup notification overlay lives
# for about fifteen seconds and is 9739 bytes).
#
# Turning Hyprland's own wallpaper back on costs no new package and gives
# the compositor real content to composite: measured 85267 bytes, all
# 921600 pixels non-zero, byte-identical at +15s, +30s and +60s. That is
# what makes "the frame is not blank" mean "grim captured composited
# pixels".
extraConfig = ''
misc:force_default_wallpaper = 1
misc:disable_hyprland_logo = false
misc:disable_splash_rendering = false
'';
};
# hyprctl and grim are here for the diagnostics dump and for the manual
# cross-check below, not for the code path under test.
environment.systemPackages = [
testTools
hhstream
hyprland
grim
];
# The compositor needs more room than the fake capture did, and its software
# renderer wants a CPU. The virtio GPU from gpu-session.nix is there for its
# render node and its DRM backend, not for acceleration: rendering is still
# Mesa's software path.
virtualisation = {
memorySize = 2048;
cores = 2;
diskSize = 4096;
graphics = false;
};
};
testScript = ''
import json
SOCKET = "${socketPath}"
WIDTH, HEIGHT = ${toString width}, ${toString height}
# The module pins XDG_RUNTIME_DIR; the instance signature under it is the
# only part that is not known ahead of time. Root may connect to the
# compositor's IPC socket even though it belongs to `hhstream`.
HYPRCTL_MONITORS = (
"set -eu; "
"sig=$(ls -1 /run/hyprland-headless-stream/hypr | head -n1); "
"XDG_RUNTIME_DIR=/run/hyprland-headless-stream"
" HYPRLAND_INSTANCE_SIGNATURE=$sig hyprctl -j monitors"
)
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 compositor unit comes up"):
try:
machine.wait_for_unit("hyprland-headless.service", timeout=180)
except Exception:
dump("hyprland-headless.service did not start")
raise
with subtest("the compositor reports a monitor at the configured mode"):
try:
# Proves the compositor is really driving a WIDTHxHEIGHT output
# before we blame the capture for a wrong-sized frame. Asked over
# hyprctl's JSON so the assertion is on the mode, never on a
# monitor name: the name belongs to the host's connector.
monitors = json.loads(machine.succeed(HYPRCTL_MONITORS, timeout=120))
print(json.dumps(monitors, indent=2, sort_keys=True))
assert monitors, "hyprctl reported no monitors at all"
print(
"monitors: "
+ ", ".join(
f"{m['name']} {m['width']}x{m['height']}@{m.get('refreshRate')}"
for m in monitors
)
)
assert any(
m["width"] == WIDTH and m["height"] == HEIGHT for m in monitors
), (
f"no monitor is at the configured {WIDTH}x{HEIGHT}; the wildcard "
"monitor rule did not take"
)
except Exception:
dump("compositor output not as configured")
raise
with subtest("the frame server unit comes up and publishes the socket"):
try:
machine.wait_for_unit("hyprland-headless-stream.service", timeout=180)
machine.wait_for_file(SOCKET, timeout=120)
except Exception:
dump("frame server did not publish the socket")
raise
with subtest("grim can capture the session at all"):
# Diagnostic, not an assertion: it separates "grim cannot see the
# compositor" from "the server is wrong", which are the two failures
# that look identical from the socket. The session's XDG_RUNTIME_DIR is
# the module's private one, not /run/user/<uid>, and the socket name is
# whatever the compositor bound -- so discover both, as the unit does.
# The grim path is the store one: a transient systemd unit gets a
# minimal PATH, not the guest's environment.systemPackages.
status, out = machine.execute(
"systemd-run --pipe --wait --uid=hhstream"
" --setenv=XDG_RUNTIME_DIR=/run/hyprland-headless-stream"
" --setenv=WAYLAND_DISPLAY=$(cd /run/hyprland-headless-stream"
" && ls -1 wayland-* | grep -v '\.lock$' | head -n1)"
" sh -c '${grim}/bin/grim -t png - > /tmp/direct.png' 2>&1",
timeout=120,
)
print(f"direct grim exit {status}: {out}")
print(machine.execute("stat -c 'direct.png: %s bytes' /tmp/direct.png")[1])
with subtest("the session settles into a frame with a picture in it"):
# A bounded wait for the *end of startup*, in the same spirit as
# wait_for_unit -- not a retry until something goes green. The Wayland
# socket is bound before the wallpaper texture has been uploaded and
# composited, so the very first frames off the socket can still be the
# empty field. Everything below this point is a hard assertion, made
# once, on a session that has finished coming up.
try:
machine.wait_until_succeeds(
f"hhs-assert-stream --socket {SOCKET} --frames 1 --timeout 30"
" --require-png --reject-blank",
timeout=120,
)
except Exception:
dump("the session never rendered anything but a blank field")
raise
with subtest("a frame off the socket is a real PNG of the configured size"):
try:
print(
machine.succeed(
f"hhs-assert-stream --socket {SOCKET} --frames 1 --timeout 60"
f" --expect-width {WIDTH} --expect-height {HEIGHT}"
" --expect-format image/png --require-png --reject-blank",
timeout=180,
)
)
except Exception:
dump("frame off the socket failed the PNG assertions")
raise
with subtest("the stream keeps producing frames"):
try:
print(
machine.succeed(
f"hhs-assert-stream --socket {SOCKET} --frames 3 --timeout 60"
f" --expect-width {WIDTH} --expect-height {HEIGHT}"
" --require-png --reject-blank",
timeout=240,
)
)
machine.succeed("systemctl is-active hyprland-headless-stream.service")
except Exception:
dump("the stream stopped after the first frame")
raise
'';
}