tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
nixos/lcd: support for Logitech devices
Peter Hoeg
5 years ago
cc305ede
840c782d
+81
-13
1 changed file
expand all
collapse all
unified
split
nixos
modules
hardware
logitech.nix
+81
-13
nixos/modules/hardware/logitech.nix
···
5
5
let
6
6
cfg = config.hardware.logitech;
7
7
8
8
-
in {
8
8
+
vendor = "046d";
9
9
+
10
10
+
daemon = "g15daemon";
11
11
+
12
12
+
in
13
13
+
{
14
14
+
imports = [
15
15
+
(mkRenamedOptionModule [ "hardware" "logitech" "enable" ] [ "hardware" "logitech" "wireless" "enable" ])
16
16
+
(mkRenamedOptionModule [ "hardware" "logitech" "enableGraphical" ] [ "hardware" "logitech" "wireless" "enableGraphical" ])
17
17
+
];
18
18
+
9
19
options.hardware.logitech = {
10
10
-
enable = mkEnableOption "Logitech Devices";
20
20
+
21
21
+
lcd = {
22
22
+
enable = mkEnableOption "Logitech LCD Devices";
23
23
+
24
24
+
startWhenNeeded = mkOption {
25
25
+
type = types.bool;
26
26
+
default = true;
27
27
+
description = ''
28
28
+
Only run the service when an actual supported device is plugged.
29
29
+
'';
30
30
+
};
11
31
12
12
-
enableGraphical = mkOption {
13
13
-
type = types.bool;
14
14
-
default = false;
15
15
-
description = "Enable graphical support applications.";
32
32
+
devices = mkOption {
33
33
+
type = types.listOf types.str;
34
34
+
default = [ "0a07" "c222" "c225" "c227" "c251" ];
35
35
+
description = ''
36
36
+
List of USB device ids supported by g15daemon.
37
37
+
</para>
38
38
+
<para>
39
39
+
You most likely do not need to change this.
40
40
+
'';
41
41
+
};
42
42
+
};
43
43
+
44
44
+
wireless = {
45
45
+
enable = mkEnableOption "Logitech Wireless Devices";
46
46
+
47
47
+
enableGraphical = mkOption {
48
48
+
type = types.bool;
49
49
+
default = false;
50
50
+
description = "Enable graphical support applications.";
51
51
+
};
16
52
};
17
53
};
18
54
19
19
-
config = lib.mkIf cfg.enable {
20
20
-
environment.systemPackages = [
21
21
-
pkgs.ltunify
22
22
-
] ++ lib.optional cfg.enableGraphical pkgs.solaar;
55
55
+
config = lib.mkIf (cfg.wireless.enable || cfg.lcd.enable) {
56
56
+
environment.systemPackages = []
57
57
+
++ lib.optional cfg.wireless.enable pkgs.ltunify
58
58
+
++ lib.optional cfg.wireless.enableGraphical pkgs.solaar;
59
59
+
60
60
+
services.udev = {
61
61
+
# ltunifi and solaar both provide udev rules but the most up-to-date have been split
62
62
+
# out into a dedicated derivation
63
63
+
64
64
+
packages = []
65
65
+
++ lib.optional cfg.wireless.enable pkgs.logitech-udev-rules
66
66
+
++ lib.optional cfg.lcd.enable pkgs.g15daemon;
67
67
+
68
68
+
extraRules = ''
69
69
+
# nixos: hardware.logitech.lcd
70
70
+
'' + lib.concatMapStringsSep "\n" (
71
71
+
dev:
72
72
+
''ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="${vendor}", ATTRS{idProduct}=="${dev}", TAG+="systemd", ENV{SYSTEMD_WANTS}+="${daemon}.service"''
73
73
+
) cfg.lcd.devices;
74
74
+
};
75
75
+
76
76
+
systemd.services."${daemon}" = lib.mkIf cfg.lcd.enable {
77
77
+
description = "Logitech LCD Support Daemon";
78
78
+
documentation = [ "man:g15daemon(1)" ];
79
79
+
wantedBy = lib.mkIf (! cfg.lcd.startWhenNeeded) "multi-user.target";
23
80
24
24
-
# ltunifi and solaar both provide udev rules but the most up-to-date have been split
25
25
-
# out into a dedicated derivation
26
26
-
services.udev.packages = with pkgs; [ logitech-udev-rules ];
81
81
+
serviceConfig = {
82
82
+
Type = "forking";
83
83
+
ExecStart = "${pkgs.g15daemon}/bin/g15daemon";
84
84
+
# we patch it to write to /run/g15daemon/g15daemon.pid instead of
85
85
+
# /run/g15daemon.pid so systemd will do the cleanup for us.
86
86
+
PIDFile = "/run/${daemon}/g15daemon.pid";
87
87
+
PrivateTmp = true;
88
88
+
PrivateNetwork = true;
89
89
+
ProtectHome = "tmpfs";
90
90
+
ProtectSystem = "full"; # strict doesn't work
91
91
+
RuntimeDirectory = daemon;
92
92
+
Restart = "on-failure";
93
93
+
};
94
94
+
};
27
95
};
28
96
}