LnL7 / nix-darwin

nix modules for darwin
MIT License
3.19k stars 457 forks source link

Karabiner elements stopped working after flake update, with: `virtual_hid_device_service_client connect_failed: No such file or directory` #1092

Closed archie-judd closed 1 month ago

archie-judd commented 1 month ago

Hi,

I recently updated my Nix Flake, and Karabiner Elements stopped working. Darwin is pointing at pointing Nixpkgs 24.05.

I checked the log in the UI and see repeated lines of [info] [grabber] virtual_hid_device_service_client_ connect_failed: No such file or directory after initialisation. This is the location of the error in Karabiner's source code and here is my log in the Karabiner Elements UI:

[2024-09-24 13:31:52.855] [info] [session_monitor] session_monitor_receiver_client is started.
[2024-09-24 13:31:52.861] [info] [grabber] current_console_user_id: 501
[2024-09-24 13:31:52.861] [info] [session_monitor] on_console_changed: true
[2024-09-24 13:31:52.861] [info] [session_monitor] session_monitor_receiver_client is connected.
[2024-09-24 13:31:52.861] [info] [session_monitor] connected
[2024-09-24 13:31:52.862] [info] [grabber] receiver is terminated
[2024-09-24 13:31:52.862] [info] [grabber] receiver is initialized
[2024-09-24 13:31:52.862] [info] [grabber] receiver: bound
[2024-09-24 13:31:52.862] [info] [grabber] receiver: chown socket: 501
[2024-09-24 13:31:54.081] [error] [observer] grabber_client error: Connection reset by peer
[2024-09-24 13:31:54.081] [info] [observer] grabber_client is closed.
[2024-09-24 13:31:55.169] [info] [observer] grabber_client is connected.
[2024-09-24 13:31:55.169] [info] [observer] rescan devices...
[2024-09-24 13:31:58.774] [info] [console_user_server] on_console_changed: on_console:true
[2024-09-24 13:31:58.776] [info] [console_user_server] grabber_client is started.
[2024-09-24 13:31:58.777] [info] [console_user_server] grabber_client is connected.
[2024-09-24 13:31:58.826] [info] [grabber] karabiner_console_user_server is connected.
[2024-09-24 13:31:58.827] [info] [grabber] console_user_server_client is connected: /Library/Application Support/org.pqrs/tmp/user/501/grabber_client/17f82e13974eb3d8.sock
[2024-09-24 13:31:58.827] [info] [grabber] device_grabber is started.
[2024-09-24 13:31:58.835] [info] [console_user_server] core_configuration is updated.
[2024-09-24 13:31:58.876] [info] [grabber] event_tap_monitor initialized
[2024-09-24 13:31:58.882] [info] [grabber] `system_preferences` is updated.
[2024-09-24 13:31:58.884] [info] [grabber] core_configuration is updated.
[2024-09-24 13:31:58.891] [info] [grabber] virtual_hid_device_service_client_ connect_failed: No such file or directory
[2024-09-24 13:31:59.919] [info] [grabber] caps lock is found on Apple Internal Keyboard / Trackpad
[2024-09-24 13:31:59.919] [info] [grabber] device_grabber_details::entry event_origin_ is updated. Apple Internal Keyboard / Trackpad (device_id:4294969987): none -> grabbed_device
[2024-09-24 13:31:59.919] [warning] [grabber] virtual_hid_keyboard is not ready. Please wait for a while.
[2024-09-24 13:31:59.921] [info] [grabber] device_grabber_details::entry event_origin_ is updated. Apple Internal Keyboard / Trackpad (device_id:4294969989): none -> observed_device
[2024-09-24 13:31:59.923] [info] [grabber] Apple Internal Keyboard / Trackpad (device_id:4294969989) hid queue value monitor is started (observed).
[2024-09-24 13:31:59.923] [info] [grabber] virtual_hid_device_service_client_ connect_failed: No such file or directory
[2024-09-24 13:32:00.922] [info] [grabber] virtual_hid_device_service_client_ connect_failed: No such file or directory
[2024-09-24 13:32:00.923] [info] [grabber] virtual_hid_device_service_client_ connect_failed: No such file or directory
...

I am using the services.karabiner-elements.enable option to enable Karabiner Elements, and I'm using home-manager as follows to symlink my karabiner.json file to ~/.config/karabiner:

 home.file.".config/karabiner" = {
    source = ./karabiner;
    recursive = false;
    onChange = ''
      /bin/launchctl kickstart -k gui/`id -u`/org.pqrs.karabiner.karabiner_console_user_server
    '';
  };

I am syncing the whole folder, and restarting the karabiner_console_user_server on change, as recommended by Karabiner: https://karabiner-elements.pqrs.org/docs/manual/misc/configuration-file-path/#about-symbolic-link.

I've tried various combinations of restart / removal and even a fresh OS install, with no luck.

Many thanks for any help or information on this.

EDIT: My flake update pushed Darwin from c8d3157d1f768e382de5526bb38e74d2245cad04 to bd7d1e3912d40f799c5c0f7e5820ec950f1e0b3d which includes this change to the Karabiner service: 034c45dd0cac806b527e64c143020676e1070769. If I roll-back to c8d3157d1f768e382de5526bb38e74d2245cad04, Karabiner starts working again for me, so perhaps an issue was introduced in 034c45dd0cac806b527e64c143020676e1070769.

will-lol commented 1 month ago

Hey @archie-judd. I was the author of https://github.com/LnL7/nix-darwin/commit/034c45dd0cac806b527e64c143020676e1070769 and have created a PR to fix the issue you encountered. Would be great if you could give the change a spin on your machine and let me know how it goes.

archie-judd commented 1 month ago

Hi @will-lol, that works for me! Thanks for taking a look.