Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6510e315d4 | ||
|
|
231fa317cb |
No files matched your search
@@ -19,7 +19,9 @@ Two parts:
|
|||||||
imports = [ inputs.hhstream.nixosModules.default ];
|
imports = [ inputs.hhstream.nixosModules.default ];
|
||||||
services.hyprland-headless-stream = {
|
services.hyprland-headless-stream = {
|
||||||
enable = true;
|
enable = true;
|
||||||
outputs = [ { name = "HEADLESS-1"; width = 1280; height = 720; refresh = 30; } ];
|
# Optional: the default is one 1280x720@30 rule with an empty name, which
|
||||||
|
# is Hyprland's wildcard and applies to whatever outputs the GPU has.
|
||||||
|
outputs = [ { width = 1920; height = 1080; refresh = 60; } ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -11,14 +11,15 @@
|
|||||||
#
|
#
|
||||||
# and systemd restarts it until the test's timeout expires. `CBackend::create()`
|
# 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
|
# 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
|
# needs three separate things. Two of them are hardware the bare test machine
|
||||||
# one of the blocks below, and each was confirmed in the guest by removing it
|
# does not have and are the blocks below; the third -- a seat that is not bound
|
||||||
# again and watching the compositor die on the next line down.
|
# to a VT -- is true of this session on any host, so it lives in nix/module.nix
|
||||||
|
# as `SEATD_VTBOUND=0` on the compositor unit rather than here.
|
||||||
#
|
#
|
||||||
# A note for whoever hits this next: none of it is visible in the journal until
|
# 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
|
# 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
|
# by default and the abort is all that survives. That is how the three causes
|
||||||
# below were separated.
|
# were separated.
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
# 1. A DRM render node.
|
# 1. A DRM render node.
|
||||||
@@ -49,36 +50,4 @@
|
|||||||
# ERR from aquamarine ]: Couldn't open a GBM device at fd 21
|
# ERR from aquamarine ]: Couldn't open a GBM device at fd 21
|
||||||
# CRIT from aquamarine ]: Cannot open backend: no allocator available
|
# CRIT from aquamarine ]: Cannot open backend: no allocator available
|
||||||
hardware.graphics.enable = true;
|
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";
|
|
||||||
}
|
}
|
||||||
+6
-2
@@ -24,7 +24,9 @@ testers.runNixOSTest {
|
|||||||
|
|
||||||
nodes.machine = {
|
nodes.machine = {
|
||||||
# gpu-session.nix is what makes the compositor able to start at all; see
|
# 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.
|
# 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 ];
|
imports = [ hhsModule ./lib/gpu-session.nix ];
|
||||||
|
|
||||||
services.hyprland-headless-stream = {
|
services.hyprland-headless-stream = {
|
||||||
@@ -35,9 +37,11 @@ testers.runNixOSTest {
|
|||||||
inherit socketPath;
|
inherit socketPath;
|
||||||
frameRate = fps;
|
frameRate = fps;
|
||||||
format = "png";
|
format = "png";
|
||||||
|
# The fake capture fixes the frame size, so the monitor rule does not
|
||||||
|
# matter here -- but it must not be a name no connector has either, or
|
||||||
|
# this file would keep advertising a shape that does nothing.
|
||||||
outputs = [
|
outputs = [
|
||||||
{
|
{
|
||||||
name = "HEADLESS-1";
|
|
||||||
inherit width height;
|
inherit width height;
|
||||||
refresh = fps;
|
refresh = fps;
|
||||||
}
|
}
|
||||||
|
|||||||
+98
-23
@@ -3,9 +3,13 @@
|
|||||||
# compositor through grim.
|
# compositor through grim.
|
||||||
#
|
#
|
||||||
# This is the check expected to be flaky, so it is deliberately impatient: every
|
# This is the check expected to be flaky, so it is deliberately impatient: every
|
||||||
# wait has a bounded timeout, nothing is retried in a loop, and any failure dumps
|
# wait has a bounded timeout, no assertion is retried, and any failure dumps the
|
||||||
# the compositor's log and `hyprctl monitors` before it propagates. A flake you
|
# compositor's log and `hyprctl monitors` before it propagates. A flake you can
|
||||||
# can read is worth more than a flake that eventually goes green.
|
# 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,
|
testers,
|
||||||
hhstream,
|
hhstream,
|
||||||
@@ -25,7 +29,9 @@ testers.runNixOSTest {
|
|||||||
|
|
||||||
nodes.machine = {
|
nodes.machine = {
|
||||||
# gpu-session.nix is what makes the compositor able to start at all; see
|
# 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.
|
# 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 ];
|
imports = [ hhsModule ./lib/gpu-session.nix ];
|
||||||
|
|
||||||
services.hyprland-headless-stream = {
|
services.hyprland-headless-stream = {
|
||||||
@@ -35,14 +41,42 @@ testers.runNixOSTest {
|
|||||||
inherit socketPath;
|
inherit socketPath;
|
||||||
frameRate = fps;
|
frameRate = fps;
|
||||||
format = "png";
|
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 = [
|
outputs = [
|
||||||
{
|
{
|
||||||
name = "HEADLESS-1";
|
|
||||||
inherit width height;
|
inherit width height;
|
||||||
refresh = fps;
|
refresh = fps;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
# No captureCommand: the module's default (grim) is the point of this check.
|
# 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
|
# hyprctl and grim are here for the diagnostics dump and for the manual
|
||||||
@@ -67,9 +101,21 @@ testers.runNixOSTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
|
import json
|
||||||
|
|
||||||
SOCKET = "${socketPath}"
|
SOCKET = "${socketPath}"
|
||||||
WIDTH, HEIGHT = ${toString width}, ${toString height}
|
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):
|
def dump(label):
|
||||||
print(f"########## diagnostics: {label} ##########")
|
print(f"########## diagnostics: {label} ##########")
|
||||||
@@ -87,17 +133,27 @@ testers.runNixOSTest {
|
|||||||
dump("hyprland-headless.service did not start")
|
dump("hyprland-headless.service did not start")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
with subtest("the compositor reports the configured headless output"):
|
with subtest("the compositor reports a monitor at the configured mode"):
|
||||||
try:
|
try:
|
||||||
# Proves the compositor is really running a 1280x720 HEADLESS-1
|
# Proves the compositor is really driving a WIDTHxHEIGHT output
|
||||||
# before we blame the capture for a wrong-sized frame.
|
# before we blame the capture for a wrong-sized frame. Asked over
|
||||||
out = machine.succeed("hhs-hyprland-diagnostics", timeout=120)
|
# hyprctl's JSON so the assertion is on the mode, never on a
|
||||||
print(out)
|
# monitor name: the name belongs to the host's connector.
|
||||||
assert "HEADLESS-1" in out, (
|
monitors = json.loads(machine.succeed(HYPRCTL_MONITORS, timeout=120))
|
||||||
"hyprctl never reported a HEADLESS-1 monitor; see the dump above"
|
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 f"{WIDTH}x{HEIGHT}" in out, (
|
)
|
||||||
f"hyprctl never reported a {WIDTH}x{HEIGHT} mode; see the dump above"
|
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:
|
except Exception:
|
||||||
dump("compositor output not as configured")
|
dump("compositor output not as configured")
|
||||||
@@ -112,20 +168,39 @@ testers.runNixOSTest {
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
with subtest("grim can capture the session at all"):
|
with subtest("grim can capture the session at all"):
|
||||||
# Separates "grim cannot see the compositor" from "the server is wrong",
|
# Diagnostic, not an assertion: it separates "grim cannot see the
|
||||||
# which are the two failures that look identical from the socket.
|
# compositor" from "the server is wrong", which are the two failures
|
||||||
try:
|
# that look identical from the socket. The session's XDG_RUNTIME_DIR is
|
||||||
print(
|
# the module's private one, not /run/user/<uid>, and the socket name is
|
||||||
machine.succeed(
|
# 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"
|
"systemd-run --pipe --wait --uid=hhstream"
|
||||||
" --setenv=XDG_RUNTIME_DIR=/run/user/$(id -u hhstream)"
|
" --setenv=XDG_RUNTIME_DIR=/run/hyprland-headless-stream"
|
||||||
" grim -t png /tmp/direct.png 2>&1 || true",
|
" --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,
|
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,
|
||||||
)
|
)
|
||||||
print(machine.execute("stat -c '%s bytes' /tmp/direct.png")[1])
|
|
||||||
except Exception:
|
except Exception:
|
||||||
dump("direct grim capture failed")
|
dump("the session never rendered anything but a blank field")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
with subtest("a frame off the socket is a real PNG of the configured size"):
|
with subtest("a frame off the socket is a real PNG of the configured size"):
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ Namespace: `services.hyprland-headless-stream`
|
|||||||
| `user` / `group` | str | `hhstream` | owner of the session and the socket |
|
| `user` / `group` | str | `hhstream` | owner of the session and the socket |
|
||||||
| `frameRate` | int | `30` | capture target, becomes `fps` in Hello |
|
| `frameRate` | int | `30` | capture target, becomes `fps` in Hello |
|
||||||
| `format` | enum `png`/`jpeg` | `png` | frame encoding |
|
| `format` | enum `png`/`jpeg` | `png` | frame encoding |
|
||||||
| `outputs` | list of attrsets | one 1280×720@30 `HEADLESS-1` | virtual monitors: `name`, `width`, `height`, `refresh`, `scale` |
|
| `outputs` | list of attrsets | one 1280×720@30 rule with an empty `name` | monitor rules applied to the outputs the machine has: `name`, `width`, `height`, `refresh`, `scale`. `name` is a regex matched against the real connector names (`eDP-1`, `Virtual-1`, …) and **empty means every output**; a name no connector has is silently ignored. The compositor never creates an output — a session started by this module drives the host's GPU. |
|
||||||
| `extraConfig` | str | `""` | extra lines appended to `hyprland.conf` |
|
| `extraConfig` | str | `""` | extra lines appended to `hyprland.conf` |
|
||||||
| `hyprlandPackage` | package | `pkgs.hyprland` | which compositor |
|
| `hyprlandPackage` | package | `pkgs.hyprland` | which compositor |
|
||||||
| `package` | package | the flake's own build | the frame server/client |
|
| `package` | package | the flake's own build | the frame server/client |
|
||||||
|
|||||||
+14
-3
@@ -9,14 +9,25 @@
|
|||||||
extraConfig,
|
extraConfig,
|
||||||
}: let
|
}: let
|
||||||
# `monitor = <name>, <width>x<height>@<refresh>, auto, <scale>` -- "auto"
|
# `monitor = <name>, <width>x<height>@<refresh>, auto, <scale>` -- "auto"
|
||||||
# lets the compositor lay the virtual outputs out left to right.
|
# lets the compositor lay the outputs out left to right.
|
||||||
|
#
|
||||||
|
# The name is a *rule selector*, not an output the compositor will create: it
|
||||||
|
# is matched as a regex against the names the backend hands up (`eDP-1`,
|
||||||
|
# `Virtual-1`, ...). Hyprland never invents an output to satisfy a rule, so a
|
||||||
|
# name that no connector has is a rule that is silently ignored.
|
||||||
|
#
|
||||||
|
# An empty name is the wildcard form -- the same shape as Hyprland's own
|
||||||
|
# shipped `monitor=,preferred,auto,1` -- and applies to every output the
|
||||||
|
# machine actually has. That is what a session which does not know the host's
|
||||||
|
# connector names wants, and it is the module's default.
|
||||||
monitorLine = o: "monitor = ${o.name}, ${toString o.width}x${toString o.height}@${toString o.refresh}, auto, ${toString o.scale}";
|
monitorLine = o: "monitor = ${o.name}, ${toString o.width}x${toString o.height}@${toString o.refresh}, auto, ${toString o.scale}";
|
||||||
in ''
|
in ''
|
||||||
# Generated by services.hyprland-headless-stream. Do not edit.
|
# Generated by services.hyprland-headless-stream. Do not edit.
|
||||||
#
|
#
|
||||||
# There is no seat, no libinput device, no cursor and no human here: the only
|
# There is no seat, no libinput device, no cursor and no human here: the only
|
||||||
# consumer of this session is the frame server. Everything below either
|
# consumer of this session is the frame server. Everything below either sets
|
||||||
# creates the virtual outputs or switches off something that assumes a user.
|
# the mode of the outputs this machine has or switches off something that
|
||||||
|
# assumes a user.
|
||||||
|
|
||||||
${lib.concatMapStringsSep "\n" monitorLine outputs}
|
${lib.concatMapStringsSep "\n" monitorLine outputs}
|
||||||
|
|
||||||
|
|||||||
+109
-30
@@ -20,32 +20,67 @@ let
|
|||||||
socketDir = builtins.dirOf cfg.socketPath;
|
socketDir = builtins.dirOf cfg.socketPath;
|
||||||
|
|
||||||
# Hyprland refuses `--socket` unless it is paired with `--wayland-fd` (that
|
# Hyprland refuses `--socket` unless it is paired with `--wayland-fd` (that
|
||||||
# pair is the socket-handover path), so the name is not ours to choose: the
|
# pair is the socket-handover path), so the socket name is not ours to choose:
|
||||||
# compositor calls wl_display_add_socket_auto, which takes the first free
|
# the compositor calls wl_display_add_socket_auto, which takes the first free
|
||||||
# `wayland-N` starting at 0. The runtime directory is private to this
|
# `wayland-N` starting at 0.
|
||||||
# session, so that is always `wayland-0`.
|
#
|
||||||
waylandDisplay = "wayland-0";
|
# N is therefore not fixed. The runtime directory is preserved across restarts
|
||||||
|
# (`RuntimeDirectoryPreserve=yes`), so a crashed compositor leaves its
|
||||||
|
# `wayland-0` behind and the next start binds `wayland-1` — measured in the VM
|
||||||
|
# test, where the frame server then waited forever for a socket that would
|
||||||
|
# never exist. Neither unit may hardcode the name:
|
||||||
|
#
|
||||||
|
# * the compositor clears leftover sockets first (the directory is private to
|
||||||
|
# this session, so nothing else can own them) — that alone makes it
|
||||||
|
# `wayland-0` again, but the units below do not depend on that;
|
||||||
|
# * the server discovers whichever socket is actually there.
|
||||||
|
clearStaleSockets = pkgs.writeShellScript "hhstream-clear-stale-sockets" ''
|
||||||
|
for stale in "$XDG_RUNTIME_DIR"/wayland-* "$XDG_RUNTIME_DIR"/wayland-*.lock; do
|
||||||
|
if [ -e "$stale" ]; then
|
||||||
|
${lib.getExe' pkgs.coreutils "rm"} -f "$stale"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Exit 0 once *any* Wayland socket is bound, and print its name so callers that
|
||||||
|
# want it do not have to glob again.
|
||||||
|
findSession = pkgs.writeShellScript "hhstream-find-session" ''
|
||||||
|
for _ in $(${lib.getExe' pkgs.coreutils "seq"} 1 300); do
|
||||||
|
for candidate in "$XDG_RUNTIME_DIR"/wayland-*; do
|
||||||
|
if [ -S "$candidate" ]; then
|
||||||
|
echo "''${candidate##*/}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
${lib.getExe' pkgs.coreutils "sleep"} 0.1
|
||||||
|
done
|
||||||
|
echo "no Wayland socket in $XDG_RUNTIME_DIR after 30s; is the compositor up?" >&2
|
||||||
|
exit 1
|
||||||
|
'';
|
||||||
|
|
||||||
|
# The server needs WAYLAND_DISPLAY pointing at the socket the compositor
|
||||||
|
# actually bound. This cannot be an `Environment=` line, because the name is
|
||||||
|
# only known once the compositor is up — systemd's ExecStartPre cannot export
|
||||||
|
# into the main process.
|
||||||
|
execServer = pkgs.writeShellScript "hhstream-exec-server" ''
|
||||||
|
for candidate in "$XDG_RUNTIME_DIR"/wayland-*; do
|
||||||
|
if [ -S "$candidate" ]; then
|
||||||
|
export WAYLAND_DISPLAY="''${candidate##*/}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exec ${lib.getExe' cfg.package "hhstream-server"} "$@"
|
||||||
|
'';
|
||||||
hyprlandConf = pkgs.writeText "hyprland.conf" (import ./hyprland-conf.nix {
|
hyprlandConf = pkgs.writeText "hyprland.conf" (import ./hyprland-conf.nix {
|
||||||
inherit lib;
|
inherit lib;
|
||||||
inherit (cfg) outputs extraConfig;
|
inherit (cfg) outputs extraConfig;
|
||||||
});
|
});
|
||||||
|
|
||||||
# `BindsTo=` already stops the frame server when the compositor goes away,
|
# `BindsTo=` already stops the frame server when the compositor goes away, but
|
||||||
# but the compositor is only *ready* once its Wayland socket is bound. The
|
# the compositor is only *ready* once its Wayland socket is bound. The
|
||||||
# compositor unit is `Type=notify`, so this is a second line of defence for
|
# compositor unit is `Type=notify`, so `findSession` above is a second line of
|
||||||
# compositor builds that do not sd_notify.
|
# defence for compositor builds that do not sd_notify, and it is why this is
|
||||||
waitForSession = pkgs.writeShellScript "hhstream-wait-for-session" ''
|
# not a plain `After=` ordering.
|
||||||
socket="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
|
|
||||||
for _ in $(${lib.getExe' pkgs.coreutils "seq"} 1 300); do
|
|
||||||
if [ -S "$socket" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
${lib.getExe' pkgs.coreutils "sleep"} 0.1
|
|
||||||
done
|
|
||||||
echo "no Wayland socket at $socket after 30s; is the compositor up?" >&2
|
|
||||||
exit 1
|
|
||||||
'';
|
|
||||||
|
|
||||||
serverArgs =
|
serverArgs =
|
||||||
[
|
[
|
||||||
@@ -136,7 +171,16 @@ in {
|
|||||||
outputs = lib.mkOption {
|
outputs = lib.mkOption {
|
||||||
type = lib.types.listOf (lib.types.submodule {
|
type = lib.types.listOf (lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {type = lib.types.str;};
|
name = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "";
|
||||||
|
description = ''
|
||||||
|
Regex matched against the names of the outputs this machine has
|
||||||
|
(`eDP-1`, `Virtual-1`, ...). Empty is Hyprland's wildcard form and
|
||||||
|
matches every output; a name no connector has is a rule that is
|
||||||
|
silently ignored.
|
||||||
|
'';
|
||||||
|
};
|
||||||
width = lib.mkOption {
|
width = lib.mkOption {
|
||||||
type = lib.types.ints.positive;
|
type = lib.types.ints.positive;
|
||||||
default = 1280;
|
default = 1280;
|
||||||
@@ -160,14 +204,26 @@ in {
|
|||||||
});
|
});
|
||||||
default = [
|
default = [
|
||||||
{
|
{
|
||||||
name = "HEADLESS-1";
|
name = "";
|
||||||
width = 1280;
|
width = 1280;
|
||||||
height = 720;
|
height = 720;
|
||||||
refresh = 30;
|
refresh = 30;
|
||||||
scale = 1.0;
|
scale = 1.0;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
description = "Virtual monitors the compositor should create.";
|
description = ''
|
||||||
|
Monitor rules applied to the outputs the machine has. Each entry becomes
|
||||||
|
one `monitor = <name>, <width>x<height>@<refresh>, auto, <scale>` line.
|
||||||
|
|
||||||
|
These are *not* outputs the compositor creates: aquamarine's headless
|
||||||
|
backend has no allocator of its own and rides on the DRM backend, so a
|
||||||
|
session started by this module always has the GPU's own connectors and
|
||||||
|
whatever names the host gives them. The default therefore uses the empty
|
||||||
|
name -- Hyprland's wildcard, as in its own shipped
|
||||||
|
`monitor=,preferred,auto,1` -- so that `enable = true` alone gives a
|
||||||
|
session at a known size on any machine. Naming a connector that does not
|
||||||
|
exist is not an error; the rule is simply never applied.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = lib.mkOption {
|
extraConfig = lib.mkOption {
|
||||||
@@ -236,8 +292,8 @@ in {
|
|||||||
|
|
||||||
# No WAYLAND_DISPLAY and no DISPLAY here on purpose: with either set the
|
# No WAYLAND_DISPLAY and no DISPLAY here on purpose: with either set the
|
||||||
# compositor would pick its nested backend and try to connect to a parent
|
# compositor would pick its nested backend and try to connect to a parent
|
||||||
# session. With no seat and no DRM device it falls back to headless,
|
# session. Without them it drives DRM directly, and the monitor rules in
|
||||||
# which is exactly what the virtual outputs in hyprland.conf want.
|
# hyprland.conf set the mode of whatever connectors it finds there.
|
||||||
environment =
|
environment =
|
||||||
sessionEnvironment
|
sessionEnvironment
|
||||||
// {
|
// {
|
||||||
@@ -250,6 +306,26 @@ in {
|
|||||||
WLR_BACKENDS = "headless";
|
WLR_BACKENDS = "headless";
|
||||||
WLR_LIBINPUT_NO_DEVICES = "1";
|
WLR_LIBINPUT_NO_DEVICES = "1";
|
||||||
WLR_RENDERER_ALLOW_SOFTWARE = "1";
|
WLR_RENDERER_ALLOW_SOFTWARE = "1";
|
||||||
|
|
||||||
|
# Ask libseat's embedded seatd for a seat with no VT.
|
||||||
|
#
|
||||||
|
# This unit is a system service, not a login, so libseat finds no
|
||||||
|
# /run/seatd.sock and no logind session and falls back to the seatd it
|
||||||
|
# links in -- whose seat is VT-bound by default. That seatd then opens
|
||||||
|
# /dev/tty0, which `cfg.user` cannot, so its client never goes active
|
||||||
|
# and every device open is refused:
|
||||||
|
#
|
||||||
|
# [libseat] Could not open target tty: Permission denied
|
||||||
|
# [libseat] Could not open VT for client
|
||||||
|
# libseat: Couldn't open device at /dev/dri/card0
|
||||||
|
# drm: Found no gpus to use, cannot continue
|
||||||
|
#
|
||||||
|
# and with the DRM backend gone there is no allocator, so
|
||||||
|
# `CBackend::create()` aborts -- the headless backend takes its
|
||||||
|
# allocator from the DRM one. SEATD_VTBOUND=0 (seatd/server.c) is the
|
||||||
|
# truth about this session on any host: there is no terminal to switch
|
||||||
|
# away from.
|
||||||
|
SEATD_VTBOUND = "0";
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
@@ -260,6 +336,10 @@ in {
|
|||||||
Type = "notify";
|
Type = "notify";
|
||||||
NotifyAccess = "all";
|
NotifyAccess = "all";
|
||||||
TimeoutStartSec = 60;
|
TimeoutStartSec = 60;
|
||||||
|
# A preserved runtime directory can still hold the previous run's
|
||||||
|
# sockets, and that would push the new session to `wayland-1` (and
|
||||||
|
# leave the server waiting on a dead one).
|
||||||
|
ExecStartPre = "${clearStaleSockets}";
|
||||||
ExecStart = lib.escapeShellArgs [
|
ExecStart = lib.escapeShellArgs [
|
||||||
(lib.getExe cfg.hyprlandPackage)
|
(lib.getExe cfg.hyprlandPackage)
|
||||||
"--config"
|
"--config"
|
||||||
@@ -280,7 +360,8 @@ in {
|
|||||||
environment =
|
environment =
|
||||||
sessionEnvironment
|
sessionEnvironment
|
||||||
// {
|
// {
|
||||||
WAYLAND_DISPLAY = waylandDisplay;
|
# WAYLAND_DISPLAY is set by `execServer` at start, because the socket
|
||||||
|
# name is only known once the compositor has bound it.
|
||||||
PYTHONUNBUFFERED = "1";
|
PYTHONUNBUFFERED = "1";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -288,10 +369,8 @@ in {
|
|||||||
commonServiceConfig
|
commonServiceConfig
|
||||||
// {
|
// {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
ExecStartPre = "${waitForSession}";
|
ExecStartPre = "${findSession} >/dev/null";
|
||||||
ExecStart = lib.escapeShellArgs (
|
ExecStart = lib.escapeShellArgs ([execServer] ++ serverArgs);
|
||||||
[(lib.getExe' cfg.package "hhstream-server")] ++ serverArgs
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user