Unverified Commit bba54c49 authored by Lin Jian's avatar Lin Jian Committed by GitHub
Browse files

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

nixos/kanata: add default value, doc and warning for devices
parents 9207b884 c5ba4c68
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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;