NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.24k stars 14.22k forks source link

input-remapper - ERROR: Request to autoload ... before a user told the service about their session using set_config_dir #304006

Closed TimoVerbrugghe closed 7 months ago

TimoVerbrugghe commented 7 months ago

Describe the bug

I'm using input-remapper to remap a key combination on my xbox controller (L3 + R3) to ALT-F4 in order to more easily close applications on my HTPC.

Defined input-remapper in my nixos configuration:

  # Enable input-remapper
  services.input-remapper = {
    enable = true;

    ## Enable built-in udev rules for when Xbox Controller is plugged in/connected through sunshine
    enableUdevRules = true;
  };

And set up the rules through the input-remapper-gtk graphical UI. This was working.

However, when rebooting the machine, the rules do not load in and systemctl status input-remapper says that it cannot autoload the rules:

[root@gamer:/home/gamer]# systemctl status input-remapper
● input-remapper.service - Service to inject keycodes without the GUI application
     Loaded: loaded (/etc/systemd/system/input-remapper.service; enabled; preset: enabled)
    Drop-In: /nix/store/nw5zirqqw9kiq03djnkfgdkkxx3i97jx-system-units/input-remapper.service.d
             └─overrides.conf
     Active: active (running) since Sun 2024-04-14 13:05:29 CEST; 38s ago
   Main PID: 1110 (.input-remapper)
         IP: 0B in, 0B out
         IO: 2.5M read, 0B written
      Tasks: 5 (limit: 38257)
     Memory: 31.8M (peak: 32.3M)
        CPU: 215ms
     CGroup: /system.slice/input-remapper.service
             ├─1110 /nix/store/gd3shnza1i50zn8zs04fa729ribr88m9-python3-3.11.8/bin/python3 /nix/store/lfkk1vqblrg36saaa6chivl0w4j7709c-input-remapper-2.0.1/bin/.input-remapper-service-wrapped
             └─1277 /nix/store/gd3shnza1i50zn8zs04fa729ribr88m9-python3-3.11.8/bin/python3 /nix/store/lfkk1vqblrg36saaa6chivl0w4j7709c-input-remapper-2.0.1/bin/.input-remapper-service-wrapped

Apr 14 13:05:29 gamer input-remapper-service[1110]: python-evdev 1.7.0
Apr 14 13:05:29 gamer systemd[1]: Started Service to inject keycodes without the GUI application.
Apr 14 13:05:32 gamer input-remapper-service[1110]: Request to autoload for "Mouse passthrough"
Apr 14 13:05:32 gamer input-remapper-service[1110]: ERROR: Request to autoload "Mouse passthrough" before a user told the service about their session using set_config_dir
Apr 14 13:05:32 gamer input-remapper-service[1110]: Request to autoload for "Mouse passthrough"
Apr 14 13:05:32 gamer input-remapper-service[1110]: ERROR: Request to autoload "Mouse passthrough" before a user told the service about their session using set_config_dir
Apr 14 13:05:32 gamer input-remapper-service[1110]: Request to autoload for "Logitech Wireless Mouse PID:4038"
Apr 14 13:05:32 gamer input-remapper-service[1110]: ERROR: Request to autoload "Logitech Wireless Mouse PID:4038" before a user told the service about their session using set_config_dir
Apr 14 13:05:54 gamer input-remapper-service[1110]: Request to autoload for "Microsoft X-Box 360 pad"
Apr 14 13:05:54 gamer input-remapper-service[1110]: ERROR: Request to autoload "Microsoft X-Box 360 pad" before a user told the service about their session using set_config_dir

If I try to stop and start the input-remapper service, it still gives me the same error. HOWEVER, when I stop the input-remapper service (systemctl stop input-remapper.service) and then start the program manually (with input-remapper-service) then the rules do load in when I connect my controller

[root@gamer:/home/gamer]# input-remapper-service
input-remapper-service 2.0.1 2.0.1 https://github.com/sezanzeb/input-remapper
python-evdev 1.7.0
Loaded config from "/home/gamer/.config/input-remapper-2/config.json"
Request to autoload for "Microsoft X-Box 360 pad"
Found "Sleep Button", "Microsoft Microsoft® Nano Transceiver v2.0", "ASRock LED Controller", "Logitech Wireless Mouse PID:4038", "Mouse passthrough", "Microsoft X-Box 360 pad"
Autoloading for "Microsoft X-Box 360 pad"
Request to start injecting for "Microsoft X-Box 360 pad"
Loading preset from "/home/gamer/.config/input-remapper-2/presets/Microsoft X-Box 360 pad/Quit Application.json"
Starting injecting the preset for "Microsoft X-Box 360 pad"

I am autologging into my gamer account (using services.autologin.user = "gamer"), don't know if that could be the cause of this? However, I find it strange that stopping and starting the service after I've logged in doesn't work, but manually starting the program does...

Steps To Reproduce

Steps to reproduce the behavior:

  1. Set up user autologin with option services.autologin.user = ""; (don't know if this is required to trigger the error)
  2. Set up input-remapper service with services.input-remapper.enable = true; and use udevrules with enableUdevRules = true;
  3. Set up a rule through input-remapper-gtk
  4. Reboot the machine

Expected behavior

I would expect the systemd service to autoload the rules just as it does when I manually start input-remapper-service from the command line

Screenshots

If applicable, add screenshots to help explain your problem.

Notify maintainers

@LunNova

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[root@gamer:/home/gamer]# nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.5, NixOS, 24.05 (Uakari), 24.05.20240410.1042fd8`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/r1g09wfd968168f6drdl7agfaf3msik4-source`

Add a :+1: reaction to issues you find important.

LunNova commented 7 months ago

The input-remapper remapper service that's part of the system doesn't know which config to use until a user logs in and sets a config folder to use. As far as I can tell this is an intentional design decision for input-remapper, it wants to be multi-user and when you log out and log in as a different user a different config can be loaded.

If you use home-manager something like this works to automate launching the user part of input-remapper on login, assuming your desktop environment supports xdg autostart. An autostart desktop file is the upstream supported way to set it up.

  xdg.configFile."autostart/input-mapper-autoload.desktop" = lib.mkIf nixosConfig.services.input-remapper.enable {
    source = "${nixosConfig.services.input-remapper.package}/share/applications/input-remapper-autoload.desktop";
  };

Otherwise, launching the input remapper GUI or adding a systemd user service that loads the user config when you log in should also work.

TimoVerbrugghe commented 7 months ago

Thanks @LunNova for the quick response! I've used home-manager in order to run the input-remapper-autoload.desktop file to solve my issue.

I also tried to create an user systemd service that would load the config but there I encountered the same issue as mentioned in my first post, maybe it had to do with autologin... But anyway: doing it through home manager worked.

nixos-discourse commented 6 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/input-remapper-not-working-as-expected/44459/2