summary refs log tree commit diff
path: root/nixos/modules/services/misc/tp-auto-kbbl.nix
blob: 59018f7f81ffa3b7f383a5aba4f92dcf8a6de3e2 (plain) (blame)
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
{ config, lib, pkgs, ... }:

with lib;

let cfg = config.services.tp-auto-kbbl;

in {
  meta.maintainers = with maintainers; [ sebtm ];

  options = {
    services.tp-auto-kbbl = {
      enable = mkEnableOption "Auto toggle keyboard back-lighting on Thinkpads (and maybe other laptops) for Linux";

      package = mkOption {
        type = types.package;
        default = pkgs.tp-auto-kbbl;
        defaultText = literalExpression "pkgs.tp-auto-kbbl";
        description = "Package providing <command>tp-auto-kbbl</command>.";
      };

      arguments = mkOption {
        type = types.listOf types.str;
        default = [ ];
        description = ''
          List of arguments appended to <literal>./tp-auto-kbbl --device [device] [arguments]</literal>
        '';
      };

      device = mkOption {
        type = types.str;
        default = "/dev/input/event0";
        description = "Device watched for activities.";
      };

    };
  };

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

    systemd.services.tp-auto-kbbl = {
      serviceConfig = {
        ExecStart = concatStringsSep " "
          ([ "${cfg.package}/bin/tp-auto-kbbl" "--device ${cfg.device}" ] ++ cfg.arguments);
        Restart = "always";
        Type = "simple";
      };

      unitConfig = {
        Description = "Auto toggle keyboard backlight";
        Documentation = "https://github.com/saibotd/tp-auto-kbbl";
        After = [ "dbus.service" ];
      };

      wantedBy = [ "multi-user.target" ];
    };
  };
}