From 69a7ab07fcbf9e7ee3a0b7d3ab73e1badefc78b4 Mon Sep 17 00:00:00 2001 From: CrystalSplitter Date: Fri, 17 Jul 2026 00:05:08 -0700 Subject: [PATCH] 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. --- nixos/modules/hardware/opentabletdriver.nix | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nixos/modules/hardware/opentabletdriver.nix b/nixos/modules/hardware/opentabletdriver.nix index aac29cac7f2f..44e28b31b387 100644 --- a/nixos/modules/hardware/opentabletdriver.nix +++ b/nixos/modules/hardware/opentabletdriver.nix @@ -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; }; }; };