-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogiops.nix
114 lines (105 loc) · 3.46 KB
/
logiops.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{ config, lib, pkgs, ... }:
let
inherit (lib) mkPackageOption mkEnableOption mkIf mkOption types;
cfg = config.services.logiops;
format = pkgs.formats.libconfig { };
in
{
options.services.logiops = {
enable = mkEnableOption "logiops, an unofficial userspace driver for HID++ Logitech devices";
package = mkPackageOption pkgs "logiops" {
example = "logiops_0_2_3";
};
settings = mkOption {
type = types.submodule { freeformType = format.type; };
description = ''
Configuration for logiops.
See <https://github.com/PixlOne/logiops/wiki/Configuration> for more details.
Also see <https://github.com/PixlOne/logiops/blob/main/logid.example.cfg> for an example config.
'';
default = { };
example = {
devices = [{
name = "Wireless Mouse MX Master";
dpi = 1000;
buttons = [
{
cid = "0xc3";
action = {
type = "Gestures";
gestures = [
{
direction = "Up";
mode = "OnRelease";
action = {
type = "Keypress";
keys = [ "KEY_UP" ];
};
}
{
direction = "None";
mode = "NoPress";
}
];
};
}
{
cid = "0xc4";
action = {
type = "Keypress";
keys = [ "KEY_A" ];
};
}
];
}];
};
};
};
config = mkIf cfg.enable {
environment.etc."logid.cfg".source = format.generate "logid.cfg" cfg.settings;
systemd.services.logiops = {
description = "Logitech Configuration Daemon";
documentation = [ "https://github.com/PixlOne/logiops" ];
wantedBy = [ "multi-user.target" ];
startLimitIntervalSec = 0;
after = [ "multi-user.target" ];
wants = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/logid";
Restart = "always";
User = "root";
RuntimeDirectory = "logiops";
CapabilityBoundingSet = [ "CAP_SYS_NICE" ];
DeviceAllow = [ "/dev/uinput rw" "char-hidraw rw" ];
ProtectClock = true;
PrivateNetwork = true;
ProtectHome = true;
ProtectHostname = true;
PrivateUsers = true;
PrivateMounts = true;
PrivateTmp = true;
RestrictNamespaces = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
MemoryDenyWriteExecute = true;
RestrictRealtime = true;
LockPersonality = true;
ProtectProc = "invisible";
SystemCallFilter = [ "nice" "@system-service" "~@privileged" ];
RestrictAddressFamilies = [ "AF_NETLINK" "AF_UNIX" ];
RestrictSUIDSGID = true;
NoNewPrivileges = true;
ProtectSystem = "strict";
ProcSubset = "pid";
UMask = "0077";
};
};
# Add a `udev` rule to restart `logiops` when the mouse is connected
# https://github.com/PixlOne/logiops/issues/239#issuecomment-1044122412
services.udev.extraRules = ''
ACTION=="add", SUBSYSTEM=="input", ATTRS{id/vendor}=="046d", RUN{program}="${config.systemd.package}/bin/systemctl --no-block try-restart logiops.service"
'';
};
}