nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

Suggestion: launchd agents/daemons should have an option to prepend `/bin/wait4path /nix/store` to the script

Open lilyball opened this issue 11 months ago • 3 comments

I'm looking at modules/nix/linux-builder.nix right now and seeing it do

{
  serviceConfig = {
    ProgramArguments = [
      "/bin/sh" "-c"
      "/bin/wait4path && exec ${builderWithOverrides}/bin/create-builder"
    ];
  };
};

Searching the repo for wait4path I'm seeing this used elsewhere as well. And I expect it's something we should be doing for any launch daemon that references things from the nix store.

Given how common this is, it seems like we should just make this easy and add an extra option to the daemon/agent config for waitForNixStore. This way all these daemons could be specified using the command or script options instead of having to fall back to serviceConfig.ProgramArguments. We could even have it default to true for any config with serviceConfig.RunAtLoad == true.

lilyball avatar Sep 10 '23 22:09 lilyball

I've been wanting to do this for a while, but I don't think I'll have time to work on this change for at least another 2 months.

Feel free to make a PR, contributions are most definitely welcome :)

Enzime avatar Sep 11 '23 08:09 Enzime

Oh wow, I had no idea /bin/wait4path existed. I wonder if the absence of wait4path invocations in critical places could explain why I've found that Nix-installed executables appear to go missing briefly after a system update or restarting with "re-open windows" selected… That issue in particular is one reason I've sworn off Nix-installed yabai.

montchr avatar Sep 15 '23 19:09 montchr

@montchr most likely, yeah. I had this problem with Nix-installed fish when restoring Terminal windows, so my login shell is actually a C program that invokes /bin/wait4path /nix/store before exec'ing the real shell. When I first looked into this ages ago I couldn't find any way to force the Nix store to load before GUI apps started launching.

lilyball avatar Sep 19 '23 02:09 lilyball