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

Lin Jian c5ba4c68 ad6a4051

Changed files
+15 -1
nixos
modules
services
hardware
+15 -1
nixos/modules/services/hardware/kanata.nix
···
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;
···
};
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;