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