summaryrefslogtreecommitdiffstats
path: root/nixos/modules/hardware/opentabletdriver.nix
blob: 44e28b31b387620245520f8c42963e2a44b72a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.hardware.opentabletdriver;
in
{
  meta.maintainers = with lib.maintainers; [
    gepbird
    thiagokokada
  ];

  options = {
    hardware.opentabletdriver = {
      enable = lib.mkOption {
        default = false;
        type = lib.types.bool;
        description = ''
          Enable OpenTabletDriver udev rules, user service and blacklist kernel
          modules known to conflict with OpenTabletDriver.
        '';
      };

      blacklistedKernelModules = lib.mkOption {
        type = lib.types.listOf lib.types.str;
        default = [
          "hid-uclogic"
          "wacom"
        ];
        description = ''
          Blacklist of kernel modules known to conflict with OpenTabletDriver.
        '';
      };

      package = lib.mkPackageOption pkgs "opentabletdriver" { };

      daemon = {
        enable = lib.mkOption {
          default = true;
          type = lib.types.bool;
          description = ''
            Whether to start OpenTabletDriver daemon as a systemd user service.
          '';
        };
      };
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];

    services.udev.packages = [ cfg.package ];

    boot.blacklistedKernelModules = cfg.blacklistedKernelModules;

    systemd.user.services.opentabletdriver = lib.mkIf cfg.daemon.enable {
      description = "Open source, cross-platform, user-mode tablet driver";
      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 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;
      };
    };
  };
}