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

nixos/kanata: add default value, doc and warning for devices
This commit is contained in:
Lin Jian 2023-09-26 13:50:59 +08:00 committed by GitHub
commit bba54c4900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,8 +9,14 @@ let
options = {
devices = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "/dev/input/by-id/usb-0000_0000-event-kbd" ];
description = mdDoc "Paths to keyboard devices.";
description = mdDoc ''
Paths to keyboard devices.
An empty list, the default value, lets kanata detect which
input devices are keyboards and intercept them all.
'';
};
config = mkOption {
type = types.lines;
@ -162,6 +168,14 @@ in
};
config = mkIf cfg.enable {
warnings =
let
keyboardsWithEmptyDevices = filterAttrs (name: keyboard: keyboard.devices == [ ]) cfg.keyboards;
existEmptyDevices = length (attrNames keyboardsWithEmptyDevices) > 0;
moreThanOneKeyboard = length (attrNames cfg.keyboards) > 1;
in
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.";
hardware.uinput.enable = true;
systemd.services = mapAttrs' mkService cfg.keyboards;