TIL: How to Set the Path Variable When Using Ubuntu With Nix (Home Manager)

As per some of my recent articles, you will be aware I am using Hyprland (tiling manager) on Ubuntu and managing the config using nix (home-manager). I was having issues where for some reason it wouldn’t set the PATH variable correctly.

On my NixOS machine, the following would be fine:

snippet.sh
bind=,XF86AudioRaiseVolume,exec, volume --inc
bind=,XF86AudioLowerVolume,exec, volume --dec
bash 2 lines
"snippet.sh" 2L

However, on Ubuntu I needed to provide the full path:

snippet.sh
bind=,XF86AudioRaiseVolume,exec, ${volume}/bin/volume --inc
bash 1 line
"snippet.sh" 1L

So in the Hyprland config it would look like:

snippet.sh
bind=,XF86AudioRaiseVolume,exec, /nix/store/q1wm84g65smaq4agq7zp40q57x3534ni-volume/bin/volume --inc
bash 1 line
"snippet.sh" 1L

It was because the session was being started by GDM (gnome), and the PATH variable was not being set properly. In Wayland GDM picks up environment variables from ~/.config/environment.d/envvars.conf 1 so we can add it here.

snippet.sh
❯ bat ~/.config/environment.d/envvars.conf --plain
PATH="$PATH:/home/haseebmajid/.nix-profile/bin"
bash 2 lines
"snippet.sh" 2L

Replace haseebmajid with your username (or I guess $HOME should work). This means when we run scripts now, it will source them from this nix-profile folder. Where the binaries get symlinked, including the volume script above. So now you don’t need to specify the full path (though maybe you should 🤷)

Appendix