LnL7 / nix-darwin

nix modules for darwin
MIT License
2.82k stars 431 forks source link

Configure environment PATH variable #1080

Open niklasravnsborg opened 2 weeks ago

niklasravnsborg commented 2 weeks ago

I'm looking for a way to declaratively set the PATH environment variable used by my macOS applications. I think currently there is no option for this in nix-darwin.

Setting the PATH variable is helpful when GUI apps should use binaries of the nix-store which they can't find by default, because the default PATH variable only includes /usr/bin:/bin:/usr/sbin:/sbin.

For some context refer to this Stackoverflow answer: https://stackoverflow.com/a/70510488.

antoineco commented 2 weeks ago

It may not seem pretty, but since this is how the system module works under the hood, you may as well add your imperative command to one of the options below. It will be executed upon each activation.

https://github.com/LnL7/nix-darwin/blob/21fe31f26473c180390cfa81e3ea81aca0204c80/modules/system/activation-scripts.nix#L124-L126

Example:

    system.extraUserActivation.text = ''
      echo "setting user's persistent configuration information for launchd domains..."
      launchctl config user path /opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin
    '';
niklasravnsborg commented 1 week ago

Running sudo launchctl config user path "/Users/nik/.nix-profile/bin:/usr/bin:/bin" gives me a 'sudo launchctl config user path…' terminated by signal SIGBUS (Misaligned address error). But I guess this is not a nix problem...