2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.hardware.logitech;
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
vendor = "046d";
|
|
|
|
|
|
|
|
daemon = "g15daemon";
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
2024-09-19 14:19:46 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "hardware" "logitech" "enable" ] [ "hardware" "logitech" "wireless" "enable" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "hardware" "logitech" "enableGraphical" ] [ "hardware" "logitech" "wireless" "enableGraphical" ])
|
2020-08-20 17:08:02 +00:00
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options.hardware.logitech = {
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
lcd = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "support for Logitech LCD Devices";
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
startWhenNeeded = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-08-20 17:08:02 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
Only run the service when an actual supported device is plugged.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
devices = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2020-08-20 17:08:02 +00:00
|
|
|
default = [ "0a07" "c222" "c225" "c227" "c251" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
List of USB device ids supported by g15daemon.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
You most likely do not need to change this.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
wireless = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "support for Logitech Wireless Devices";
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
enableGraphical = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-08-20 17:08:02 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable graphical support applications.";
|
2020-08-20 17:08:02 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
config = lib.mkIf (cfg.wireless.enable || cfg.lcd.enable) {
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ lib.optional cfg.wireless.enable pkgs.ltunify
|
|
|
|
++ lib.optional cfg.wireless.enableGraphical pkgs.solaar;
|
|
|
|
|
|
|
|
services.udev = {
|
|
|
|
# ltunifi and solaar both provide udev rules but the most up-to-date have been split
|
|
|
|
# out into a dedicated derivation
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
packages = []
|
|
|
|
++ lib.optional cfg.wireless.enable pkgs.logitech-udev-rules
|
|
|
|
++ lib.optional cfg.lcd.enable pkgs.g15daemon;
|
|
|
|
|
|
|
|
extraRules = ''
|
|
|
|
# nixos: hardware.logitech.lcd
|
|
|
|
'' + lib.concatMapStringsSep "\n" (
|
|
|
|
dev:
|
|
|
|
''ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="${vendor}", ATTRS{idProduct}=="${dev}", TAG+="systemd", ENV{SYSTEMD_WANTS}+="${daemon}.service"''
|
|
|
|
) cfg.lcd.devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."${daemon}" = lib.mkIf cfg.lcd.enable {
|
|
|
|
description = "Logitech LCD Support Daemon";
|
|
|
|
documentation = [ "man:g15daemon(1)" ];
|
|
|
|
wantedBy = lib.mkIf (! cfg.lcd.startWhenNeeded) "multi-user.target";
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
ExecStart = "${pkgs.g15daemon}/bin/g15daemon";
|
|
|
|
# we patch it to write to /run/g15daemon/g15daemon.pid instead of
|
|
|
|
# /run/g15daemon.pid so systemd will do the cleanup for us.
|
|
|
|
PIDFile = "/run/${daemon}/g15daemon.pid";
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateNetwork = true;
|
|
|
|
ProtectHome = "tmpfs";
|
|
|
|
ProtectSystem = "full"; # strict doesn't work
|
|
|
|
RuntimeDirectory = daemon;
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|