nixos/opentabletdriver: Match OTD Upstream systemd environment checks

OTD requires WAYLAND_DISPLAY or DISPLAY to be set,
otherwise it assumes x11 which, on a WAYLAND display configuration,
leads to segfaults on OTD start up. Enforce an ordering
so that we wait until the session has initted before doing
anything.

Upstream has both a check for these environment variables,
as well as enforces a RestartSec=3 to prevent immediate
restarts.

Additionally, it's theoretically possible for DISPLAY to
be set before WAYLAND_DISPLAY, causing segmentation faults
on wayland set ups, so add an explicit polling condition for
that in the ExecStartPre script.
This commit is contained in:
CrystalSplitter
2026-07-17 00:05:08 -07:00
parent acd153794d
commit 69a7ab07fc

View File

@@ -61,16 +61,27 @@ in
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
unitConfig = {
After = "graphical-session.target";
ConditionEnvironment = [
"|WAYLAND_DISPLAY"
"|DISPLAY"
];
};
serviceConfig = {
Type = "simple";
# workaround for https://github.com/NixOS/nixpkgs/issues/469340
ExecStartPre = pkgs.writeShellScript "disable-for-gdm-greeter" ''
if [[ "$USER" = "gdm-greeter"* ]]; then
# workaround for https://github.com/NixOS/nixpkgs/issues/469340 and
# https://github.com/OpenTabletDriver/OpenTabletDriver/issues/4885
ExecStartPre = pkgs.writeShellScript "poll-for-non-gdm-greeter-display" ''
if [[ "$USER" = "gdm-greeter"* \
|| ( "$${XDG_SESSION_TYPE}" = wayland && -z "$${WAYLAND_DISPLAY}" ) ]]; then
exit 1
fi
'';
ExecStart = lib.getExe' cfg.package "otd-daemon";
Restart = "on-failure";
RestartSec = 3;
};
};
};