1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.services.tp-auto-kbbl;
6
7in {
8 meta.maintainers = with maintainers; [ sebtm ];
9
10 options = {
11 services.tp-auto-kbbl = {
12 enable = mkEnableOption (lib.mdDoc "Auto toggle keyboard back-lighting on Thinkpads (and maybe other laptops) for Linux");
13
14 package = mkOption {
15 type = types.package;
16 default = pkgs.tp-auto-kbbl;
17 defaultText = literalExpression "pkgs.tp-auto-kbbl";
18 description = lib.mdDoc "Package providing {command}`tp-auto-kbbl`.";
19 };
20
21 arguments = mkOption {
22 type = types.listOf types.str;
23 default = [ ];
24 description = lib.mdDoc ''
25 List of arguments appended to `./tp-auto-kbbl --device [device] [arguments]`
26 '';
27 };
28
29 device = mkOption {
30 type = types.str;
31 default = "/dev/input/event0";
32 description = lib.mdDoc "Device watched for activities.";
33 };
34
35 };
36 };
37
38 config = mkIf cfg.enable {
39 environment.systemPackages = [ cfg.package ];
40
41 systemd.services.tp-auto-kbbl = {
42 serviceConfig = {
43 ExecStart = concatStringsSep " "
44 ([ "${cfg.package}/bin/tp-auto-kbbl" "--device ${cfg.device}" ] ++ cfg.arguments);
45 Restart = "always";
46 Type = "simple";
47 };
48
49 unitConfig = {
50 Description = "Auto toggle keyboard backlight";
51 Documentation = "https://github.com/saibotd/tp-auto-kbbl";
52 After = [ "dbus.service" ];
53 };
54
55 wantedBy = [ "multi-user.target" ];
56 };
57 };
58}