Setting up $PATH for system.activationScripts


Is there any way to set up $PATH in system.activationScripts and system.userActivationScripts, so that I don’t have to keep referencing the pkg variables?

I’m working on a configuration.nix file for a media PC, and I like the idea of having all my config in one file so I have reproducible builds. The steps includes cloning a git repo and setting up a systemd timer to periodically run a script.

Right now I’m calling things like ${pkgs.git}/bin/git clone ..., and ${pkgs.curl}/bin/curl .... Is there any way I can just use git and curl in these scripts?


P.S. I’ve just started trying out NixOS today, and I’m really impressed so far!

The option environment.systemPackages may be what you are looking for. You can list all packages that you want to have in your path globally.

Hi @markuskowa, thanks for your reply! I’ve added curl to environment.systemPackages, and here is a part of my configuration.nix:

system.activationScripts = {
    exampleScript = {
      text = ''
      curl "" -o /opt/<file>.conf
      deps = [];

Here’s the error I get, because it can’t find curl:

/nix/store/4d88yynx3ajaq9rza43x2pl736q2qjlk-nixos-system-mycomputername-19.03.173495.7339bd47600/activate: line 201: curl: command not found

I just found this person who also had the same problem on StackOverflow.

I can get it to work by replacing curl with ${pkgs.curl}/bin/curl, but that’s not very ergonomic.

Thanks for your help!

OK, the systemPackages options won’t work in the activation scripts. In that case you could set the path in your script like this: PATH=$PATH:${lib.makeBinPath [ pkgs.curl ]}.

you could also do source ${} at the top of your script

1 Like

Thanks @markuskowa and @alexarice! I just tried source ${} and that works great. I like this approach since I don’t need to specify all the packages twice. Thanks for your help!

I would personally recommend listing them out again to be honest. It might save trouble down the line if you remove a program from your system packages

1 Like