1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.programs.light;
10
11in
12{
13 options = {
14 programs.light = {
15
16 enable = lib.mkOption {
17 default = false;
18 type = lib.types.bool;
19 description = ''
20 Whether to install Light backlight control command
21 and udev rules granting access to members of the "video" group.
22 '';
23 };
24
25 brightnessKeys = {
26 enable = lib.mkOption {
27 type = lib.types.bool;
28 default = false;
29 description = ''
30 Whether to enable brightness control with keyboard keys.
31
32 This is mainly useful for minimalistic (desktop) environments. You
33 may want to leave this disabled if you run a feature-rich desktop
34 environment such as KDE, GNOME or Xfce as those handle the
35 brightness keys themselves. However, enabling brightness control
36 with this setting makes the control independent of X, so the keys
37 work in non-graphical ttys, so you might want to consider using this
38 instead of the default offered by the desktop environment.
39
40 Enabling this will turn on {option}`services.actkbd`.
41 '';
42 };
43
44 step = lib.mkOption {
45 type = lib.types.int;
46 default = 10;
47 description = ''
48 The percentage value by which to increase/decrease brightness.
49 '';
50 };
51
52 minBrightness = lib.mkOption {
53 type = lib.types.numbers.between 0 100;
54 default = 0.1;
55 description = ''
56 The minimum authorized brightness value, e.g. to avoid the
57 display going dark.
58 '';
59 };
60
61 };
62
63 };
64 };
65
66 config = lib.mkIf cfg.enable {
67 environment.systemPackages = [ pkgs.light ];
68 services.udev.packages = [ pkgs.light ];
69 services.actkbd = lib.mkIf cfg.brightnessKeys.enable {
70 enable = true;
71 bindings =
72 let
73 light = "${pkgs.light}/bin/light";
74 step = builtins.toString cfg.brightnessKeys.step;
75 minBrightness = builtins.toString cfg.brightnessKeys.minBrightness;
76 in
77 [
78 {
79 keys = [ 224 ];
80 events = [ "key" ];
81 # -N is used to ensure that value >= minBrightness
82 command = "${light} -N ${minBrightness} && ${light} -U ${step}";
83 }
84 {
85 keys = [ 225 ];
86 events = [ "key" ];
87 command = "${light} -A ${step}";
88 }
89 ];
90 };
91 };
92}