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