I’m just getting started using Nix on MacOS, and am wondering about the best way to integrate with the zsh shell. I’m using nix-env to install packages, I’m not currently trying or intending to manage any of the Mac’s configuration using nix-adjacent tools (Home Manager, nix-darwin).
The things I’d like to do are:
- have zsh pick up on completions installed as part of packages installed with nix-env.
- be able to install a zsh “config”, in particular grml-zsh-config, with nix-env and use that.
I don’t have a strong opinion on whether I use the system zsh or nixpkgs.zsh.
I’ve done some searching, but I haven’t found any really clear suggestions on the best way to connect things up.
As far as I can tell, both the system zsh and the nix zsh read the MacOS zsh configuration at
/etc/zshrc, as well as the other usual configuration files (
/etc/zprofile - which confusingly mangles paths on MacOS,
Both system zsh and nix zsh add their respective
/usr/share/zsh/x.y.z/functions directories to the
$fpath meaning that the appropriate “built-in” completion functions are available to zsh. Neither system zsh nor nix zsh add nix’s
site-functions directory (
~/.nix-profile/share/zsh/site-functions) to the
$fpath, meaning that completions for installed packages are not availble.
The cleanest solution I’ve come up with so far is to manually add the appropriate
site-packages to the
~/.zshrc and also source the grml-zsh-config here. I figure that the
site-functions path should be stable, and that grml-zsh-config upgrades should “just work”. My
~/.zshrc minus some unrelated path additions:
export fpath=(/Users/jony/.nix-profile/share/zsh/site-functions $fpath) source $(nix-env -q --out-path grml-zsh-config | cut -d' ' -f3)/etc/zsh/zshrc
That seems to work, and seems reasonably clean … but I can’t help but wondering whether I’m doing it all wrong, since I don’t see anyone mentioning this sort of thing anywhere. Any thoughts from more experienced nix users?