Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skhd hot reloading doesn't work #333

Open
d12frosted opened this issue May 17, 2021 · 5 comments
Open

skhd hot reloading doesn't work #333

d12frosted opened this issue May 17, 2021 · 5 comments

Comments

@d12frosted
Copy link

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.

@danielcorin
Copy link

danielcorin commented Mar 6, 2024

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.

@Samasaur1
Copy link
Contributor

It might be easiest to just add skhd -r to system.activationScripts.postActivation:

system.activationScripts.postActivation.text = ''
   ${pkgs.skhd} -r
'';

@alexandru0-dev
Copy link

alexandru0-dev commented Apr 11, 2024

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: koekeishiya/skhd#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

@tymscar
Copy link

tymscar commented Apr 30, 2024

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?

@gshpychka
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants