From a37b3dd485168da9370228e372c3a22ff1ada7d0 Mon Sep 17 00:00:00 2001 From: Hermenix Date: Mon, 28 Sep 2026 12:28:01 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_018fJZYyS4pqxt2FC37JsFYd --- checks/lib/gpu-session.nix | 84 +++++++++++++++++++++++++++++++++++ checks/vm-basic.nix | 20 +++++++-- checks/vm-hyprland.nix | 9 ++-- tests/hyprland_diagnostics.sh | 27 +++++++++++ 4 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 checks/lib/gpu-session.nix diff --git a/checks/lib/gpu-session.nix b/checks/lib/gpu-session.nix new file mode 100644 index 0000000..b86b1b4 --- /dev/null +++ b/checks/lib/gpu-session.nix @@ -0,0 +1,84 @@ +# What a NixOS test machine has to be given before Hyprland 0.56.2 will start. +# +# Imported by both VM checks. It is a machine definition, not a test: nothing +# here relaxes anything either check asserts, it only supplies hardware and +# session facts that a default `nodes.machine` does not have. +# +# The failure it fixes is the same one every time -- the compositor aborts with +# +# terminate called after throwing an instance of 'std::runtime_error' +# what(): CBackend::create() failed! +# +# and systemd restarts it until the test's timeout expires. `CBackend::create()` +# is aquamarine's, and reading aquamarine 0.15.1 rather than guessing at it, it +# needs three separate things that a bare test machine does not provide. Each is +# one of the blocks below, and each was confirmed in the guest by removing it +# again and watching the compositor die on the next line down. +# +# A note for whoever hits this next: none of it is visible in the journal until +# you also set `debug:disable_logs = false`, because Hyprland mutes aquamarine +# by default and the abort is all that survives. That is how the three causes +# below were separated. +{ ... }: +{ + # 1. A DRM render node. + # + # `virtualisation.graphics = false` still leaves QEMU's default bochs-drm + # adapter in the guest, which offers /dev/dri/card0 and *no* renderD*. Measured + # in the guest, not assumed: + # + # (default) card0 (bochs-drm) + # -vga virtio card0, renderD128 (virtio_gpu) + # -device virtio-gpu-pci card0, card1, renderD128 (bochs + virtio) + # -vga none -device virtio-gpu-pci card0, renderD128 (virtio_gpu) + # + # `-vga virtio` *replaces* the default adapter, so it is the one-option form of + # the last line. `-device virtio-gpu-pci` on its own only *adds* a second card + # next to bochs-drm, so it would need `-vga none` beside it to leave the guest + # with a single DRM device. + virtualisation.qemu.options = [ "-vga virtio" ]; + + # 2. Mesa, where the GBM loader looks for it. + # + # aquamarine's allocator is gbm_create_device() on that node. On NixOS the GBM + # backends live under /run/opengl-driver, which only exists when + # hardware.graphics is enabled -- a test machine has it off. Without it: + # + # MESA-LOADER: failed to open dri: /run/opengl-driver/lib/gbm/dri_gbm.so: + # cannot open shared object file: No such file or directory + # ERR from aquamarine ]: Couldn't open a GBM device at fd 21 + # CRIT from aquamarine ]: Cannot open backend: no allocator available + hardware.graphics.enable = true; + + # 3. A seat that is not bound to a VT. + # + # This one is not really the test machine's business, and it is flagged rather + # than fixed: it belongs in nix/module.nix, which this slice may not edit. + # + # Only the DRM backend ever yields a buffer allocator -- + # `CHeadlessBackend::drmFD()` returns -1 unconditionally (aquamarine + # src/backend/Headless.cpp), and CBackend::start() takes the allocator from the + # first implementation with a drm fd. So "headless" here does not mean "no + # GPU": the headless backend still rides on the DRM backend's allocator, and if + # the DRM backend fails there is none, whatever /dev/dri holds. + # + # The DRM backend opens /dev/dri/card0 through libseat. For this unit libseat + # finds no /run/seatd.sock and no logind session (it is a system service, not a + # login), so it falls back to its embedded seatd -- whose seat is VT-bound by + # default. It then tries to open /dev/tty0, which the unprivileged `hhstream` + # user cannot, so the client never becomes active and every device open is + # refused: + # + # ERR ]: [libseat] [common/terminal.c:162] Could not open target tty: Permission denied + # ERR ]: [libseat] [seatd/seat.c:557] Could not open VT for client + # ERR ]: libseat: Couldn't open device at /dev/dri/card0 + # ERR ]: drm: Skipping device /sys/devices/.../drm/card0, not a KMS device + # ERR ]: drm: Found no gpus to use, cannot continue + # ERR ]: DRM Backend failed + # + # SEATD_VTBOUND=0 (seatd/server.c) asks that embedded seatd for a seat with no + # VT at all, which is the truth about this session: there is no terminal to + # switch away from. A headless session run as a system user will need this on + # any machine, not just in the test. + systemd.services.hyprland-headless.environment.SEATD_VTBOUND = "0"; +} diff --git a/checks/vm-basic.nix b/checks/vm-basic.nix index 655dd42..96a36c5 100644 --- a/checks/vm-basic.nix +++ b/checks/vm-basic.nix @@ -8,6 +8,7 @@ testers, hhstream, testTools, + python3, hhsModule, width ? 1280, height ? 720, @@ -22,7 +23,9 @@ testers.runNixOSTest { globalTimeout = 900; nodes.machine = { - imports = [ hhsModule ]; + # 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; @@ -51,12 +54,19 @@ testers.runNixOSTest { 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 = 1024; + memorySize = 2048; cores = 2; - diskSize = 3072; + diskSize = 4096; graphics = false; }; }; @@ -68,7 +78,9 @@ testers.runNixOSTest { def dump(label): print(f"########## diagnostics: {label} ##########") - print(machine.execute("hhs-hyprland-diagnostics")[1]) + status, out = machine.execute("hhs-hyprland-diagnostics", timeout=120) + print(out) + print(f"########## end diagnostics (exit {status}) ##########") start_all() diff --git a/checks/vm-hyprland.nix b/checks/vm-hyprland.nix index 5b04a46..adeb680 100644 --- a/checks/vm-hyprland.nix +++ b/checks/vm-hyprland.nix @@ -24,7 +24,9 @@ testers.runNixOSTest { globalTimeout = 1800; nodes.machine = { - imports = [ hhsModule ]; + # 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; @@ -53,8 +55,9 @@ testers.runNixOSTest { ]; # The compositor needs more room than the fake capture did, and its software - # renderer wants a CPU. There is still no GPU: Hyprland runs on its headless - # backend over llvmpipe. + # 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; diff --git a/tests/hyprland_diagnostics.sh b/tests/hyprland_diagnostics.sh index b884382..d0a33c6 100755 --- a/tests/hyprland_diagnostics.sh +++ b/tests/hyprland_diagnostics.sh @@ -32,6 +32,15 @@ done run systemctl --no-pager --full list-dependencies "$SERVICE_UNIT" +say "graphics devices" +# The one piece of hardware a headless Hyprland still needs. A NixOS test +# machine gets QEMU's default bochs-drm adapter, which gives a card0 and *no* +# renderD*; aquamarine's headless backend wants a render node and aborts with +# "CBackend::create() failed!" without one. So "card0 but no renderD128" here +# is the signature of a machine that needs a virtio GPU in qemu.options. +ls -l /dev/dri 2>&1 || echo "[no /dev/dri: this machine has no DRM device at all]" +run cat /proc/fb + say "socket and runtime directories" ls -la /run/hyprland-headless-stream 2>&1 || echo "[no /run/hyprland-headless-stream]" ls -la /run/user 2>&1 || echo "[no /run/user]" @@ -39,6 +48,24 @@ for d in /run/user/*; do [ -d "$d" ] && ls -la "$d" 2>&1 done +say "wayland socket vs WAYLAND_DISPLAY" +# The other silent killer: the frame server waits for +# $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY, so if the compositor bound a different +# socket name the unit just sits in ExecStartPre until the test times out, with +# a healthy compositor next to it. Print both names side by side. +systemctl show -p Environment --value "$SERVICE_UNIT" 2>&1 \ + | tr ' ' '\n' | grep -E '^(WAYLAND_DISPLAY|XDG_RUNTIME_DIR)=' \ + || echo "[no WAYLAND_DISPLAY/XDG_RUNTIME_DIR in the unit environment]" +for d in /run/hyprland-headless-stream /run/user/*; do + [ -d "$d" ] || continue + found_sock=$(find "$d" -xdev -maxdepth 1 -name 'wayland-*' ! -name '*.lock' 2>/dev/null) + if [ -n "$found_sock" ]; then + echo "bound sockets in $d: $found_sock" + else + echo "bound sockets in $d: [none]" + fi +done + say "hyprland logs" # hyprland.log lives beside the compositor's IPC sockets; -xdev keeps this out # of /nix/store and /proc.