lol

Merge pull request #255813 from linj-fork/feat-kanata-all-device

nixos/kanata: add default value, doc and warning for devices

authored by

Lin Jian and committed by
GitHub
bba54c49 9207b884

+15 -1
+15 -1
nixos/modules/services/hardware/kanata.nix
··· 9 9 options = { 10 10 devices = mkOption { 11 11 type = types.listOf types.str; 12 + default = [ ]; 12 13 example = [ "/dev/input/by-id/usb-0000_0000-event-kbd" ]; 13 - description = mdDoc "Paths to keyboard devices."; 14 + description = mdDoc '' 15 + Paths to keyboard devices. 16 + 17 + An empty list, the default value, lets kanata detect which 18 + input devices are keyboards and intercept them all. 19 + ''; 14 20 }; 15 21 config = mkOption { 16 22 type = types.lines; ··· 162 168 }; 163 169 164 170 config = mkIf cfg.enable { 171 + warnings = 172 + let 173 + keyboardsWithEmptyDevices = filterAttrs (name: keyboard: keyboard.devices == [ ]) cfg.keyboards; 174 + existEmptyDevices = length (attrNames keyboardsWithEmptyDevices) > 0; 175 + moreThanOneKeyboard = length (attrNames cfg.keyboards) > 1; 176 + in 177 + optional (existEmptyDevices && moreThanOneKeyboard) "One device can only be intercepted by one kanata instance. Setting services.kanata.keyboards.${head (attrNames keyboardsWithEmptyDevices)}.devices = [ ] and using more than one services.kanata.keyboards may cause a race condition."; 178 + 165 179 hardware.uinput.enable = true; 166 180 167 181 systemd.services = mapAttrs' mkService cfg.keyboards;