Sxhkd does not see any other services

I want to map some keymap shortcut to restart some services. For instance, typing in my terminal in NixOs:

systemctl restart --user random-background

Restart random-background service correctly and change the background.

To my surprise the same shortcut in my sxhkd config is ineffective.

"super + b" = "systemctl restart --user random-background";

Playing with other shortcut, my first assemption is that sxhkd does not know who the user is. But adding the following shortcut:

"super + e" = "systemctl --user list-units > /tmp/foo";

Create an empty files, hence suggesting that the service sxhkd does not have any visibility on other running services and cannot restart them. Also:

"super + e" = "whoami > /tmp/foo";

Does not give any output (I was expecting to output my user). Am I misunderstanding something in my analysis or are these services run as “empty” user and can’t see any other services? How can I let sxhkd run as my user and be able to restart other services?

Thanks in advance for any thoughts!

It’s likely that the environment in which sxkhd is executing commands is very minimal. Check comments of the PATH environment variable.

1 Like

Thank you gleber for your answer! You were totally right, by default sxhkd only has /home/myuser/.nix-profile/bin in its PATH. Adding the following option in my home.nix:

services.sxhkd.extraPath = "/run/current-system/sw/bin/";

grant visibility to the systemctl command and fixed the issue!
Thanks again!