I’ve added agkozak-zsh-prompt and then tried to use it to style my zsh shell prompt (without having to add a plugin manager) in configuration.nix or using Home Manager inspired by this old comment. When it came to the latter, I used the new (?) initContent option.
Anyway, I couldn’t make it work, so I fall back to the official documentation and simply added the extra line at the end of my .zshrc: source /nix/store/cyvjjpgsscgsjh9gb731ksla2zdx7adc-agkozak-zsh-prompt-3.11.4/share/zsh/site-functions/agkozak-zsh-prompt.plugin.zsh
However, this doesn’t seem to be the best way to do it on NixOS, so that’s why I am here asking for help. Does anyone know have any suggestions for a nixer way?
Hardcoding a path from /nix/store is a very bad idea. In cases like this, you want to get the path dynamically, in your case can do it with the following code:
This works for any files coming from a package, if you needed to have the full path of a binary you would do something like ${pkgs.foo}/bin/bar, or ${lib.getExe pkgs.foo} if the package in question has meta.mainProgram set.
For the record, this is because that path will disappear next time you use nix-collect-garbage (well, after an update). Nix doesn’t know you manually made something depend on the path if you don’t ask it to create the dependency.
I built the package from my nixpkgs instance with nix build nixpkgs#agkozak-zsh-prompt (this command is only if you are using nix flakes), then I just have to look at the output inside the result symlink. If you do not use flakes, you can use nix-build '<nixpkgs>' -A agkozak-zsh-prompt.
Another option is to use a tool like nix-locate :
$ nix-locate agkozak-zsh-prompt.plugin.zsh
agkozak-zsh-prompt.out 38,768 r /nix/store/x7g7fh91gwnqmmx3mx4b94wn6313if40-agkozak-zsh-prompt-3.11.4/share/zsh/site-functions/agkozak-zsh-prompt.plugin.zsh