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