summary refs log tree commit diff
path: root/nixos/modules/services/hardware
diff options
context:
space:
mode:
authorLin Jian <me@linj.tech>2023-09-18 13:54:21 +0800
committerLin Jian <me@linj.tech>2023-09-24 17:09:23 +0800
commitc5ba4c687ebef2c7286416814ff80552cc0177c4 (patch)
tree9128131bb9db70b7ace2c21bbc231af14b5ccd5b /nixos/modules/services/hardware
parentad6a4051a6750df50b4c93a76e76da02e2d11793 (diff)
downloadnixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar.gz
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar.bz2
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar.lz
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar.xz
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.tar.zst
nixpkgs-c5ba4c687ebef2c7286416814ff80552cc0177c4.zip
nixos/kanata: add default value, doc and warning for devices
Diffstat (limited to 'nixos/modules/services/hardware')
-rw-r--r--nixos/modules/services/hardware/kanata.nix16
1 files changed, 15 insertions, 1 deletions
diff --git a/nixos/modules/services/hardware/kanata.nix b/nixos/modules/services/hardware/kanata.nix
index 7d544050130..aac20c6c760 100644
--- a/nixos/modules/services/hardware/kanata.nix
+++ b/nixos/modules/services/hardware/kanata.nix
@@ -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;