nix-darwin
nix-darwin copied to clipboard
skhd hot reloading doesn't work
Seems like skhd
configurations changes in services.skhd.skhdConfig
are applied only upon system restart/manual service reload via launchctrl
.
skhd
has a feature to hot load its configurations, and for some reason that's not working.
I also tried using manual reload, but it could not lock pid-file
. Reading the sources of skhd
makes me think that the file was not properly created and unfortunately I didn't check it before restarting the service manually via lanuchctl
, which fixes the issue.
## Signal a running instance of skhd to reload its config file
$ skhd -r
skhd: could not lock pid-file! abort..
What works so far is manually restarting the service
$ launchctl stop org.nixos.skhd
$ launchctl start org.nixos.skhd
And then after every darwin-rebuild switch
I need to skhd -r
.
Any ideas how to automate it? Please let me know if you need more information.
P.S. I am using nix
, nix-darwin
and home-manager
for the second day only, so might be missing something obvious.
I am seeing similar behavior to you. I suspect it may have something to do with the symlink changing when running darwin-rebuild switch
or the home-manager
equivalent. This issue also seems to describe something similar.
I am creating a file in ~/.config
with home-manager
:
{
home.file.skhd = {
target = ".config/skhd/skhdrc";
text = ''
...
'';
}
After running darwin-rebuild switch
, the file shows up where you'd expect
❯ l.
skhdrc -> /nix/store/2scv6kjzkpn9ghmhrmg2n46yvvpdzcr4-home-manager-files/.config/skhd/skhdrc
Making changes and running darwin-rebuild switch
again changes where the symlink points, which I suspect doesn't trigger a change event to the file skhd
is watching.
❯ l.
skhdrc -> /nix/store/500pniqi49phnlhicmig8cp12ficgnmj-home-manager-files/.config/skhd/skhdrc
Running skhd -r
after darwin-rebuild switch
resolves the issue but is required for each run of darwin-rebuild switch
that modifies the skhdrc
. I suspect if I could find a way to make the symlink path stable, that might work.
It might be easiest to just add skhd -r
to system.activationScripts.postActivation
:
system.activationScripts.postActivation.text = ''
${pkgs.skhd} -r
'';
After some research i found that as the time of writing skhd doesn't support hot-reloading on symlinks. And guess how nix works? we all know LMAO The related issue: https://github.com/koekeishiya/skhd/issues/342 (pls like so we can get more attention from the dev)
My workaround solution in the meantime:
system.activationScripts.postActivation.text = ''
su - $(logname) -c '${pkgs.skhd}/bin/skhd -r'
'';
(This solution also should work on multi-user setup)
How i got there:
I got inspiration from @Samasaur1's idea but to make it work the script needs to run as the same user who is logged (`postActivation` uses root and this does not work).
Firstly i hardcoded the username using a global variable from my flake but realized that it wouldn't for people with multi-user setups (unless hardcoding every user i suppose, haven't tried it as i don't have a multi-user setup myself)
Then i found out about the logname
command which outputs who is the logged user (ignoring env vars, so it works even shell user is another one).
Hope this helped someone.
EDIT: formatting (added summary) and removed unfinished sentence
I can't get skhd to do anything in my setup. I have tried everything mentioned here, and even reboots and it does not seem like skhd is doing anything. I can see the process running, and I can see its pointed to the right config file, but it will not react to any key.
Skhd is allowed to be run in the background, and also it's enabled in Privacy & Security -> Accessibility
Could my issue be related, or should I create a new ticket?
I can't get skhd to do anything in my setup. I have tried everything mentioned here, and even reboots and it does not seem like skhd is doing anything. I can see the process running, and I can see its pointed to the right config file, but it will not react to any key.
Skhd is allowed to be run in the background, and also it's enabled in
Privacy & Security -> Accessibility
Could my issue be related, or should I create a new ticket?
Doesn't sound like your issue is with hot reloading.