I'd like to add functionality relating to the awscli command completion.

In my particular case I need to source the script from /nix/store/hvx7xqvjz7r08nsb9kssh1d9s302v3sp-awscli-1.16.106/share/zsh/site-functions/aws_zsh_completer.sh.

How can I get the store path (/nix/store/hvx7xqvjz7r08nsb9kssh1d9s302v3sp-awscli-1.16.106) for a package (awscli)? As I don't think hardcoding this reference is ideal.

5 Answers 5


You can use configuration.nix to create a symlink in /etc that points to the file you want to source. Then you simply source said symlink. For example, something like this...


environment.etc."zsh/zshrc".source = "${pkgs.awscli}/share/zsh/site-functions/aws_zsh_completer.sh";

...would create the symbolic link /etc/zsh/zshrc which would point to /nix/store/hvx7xqvjz7r08nsb9kssh1d9s302v3sp-awscli-1.16.106/share/zsh/site-functions/aws_zsh_completer.sh

Since this is done through configuration.nix, the symbolic link will get updated to the correct path each time you build the system.

Then, you can source /etc/zsh/zshrc in your ~.zshrc.


Through nix-locate , install it then update the database with nix-index:

nix-locate "PATTERN"

You could use nix eval --raw to print the store path of a package. For your example:

ls $(nix eval --raw nixpkgs.awscli)/share/zsh/site-functions/aws_zsh_completer.sh

This file will only exist if the package is already in your local nix store.

⚠️ Update in June 2022 with nix 2.8.0

This command no longer works as-is. I tried to updated it and came up with this:

ls $(nix --extra-experimental-features nix-command --extra-experimental-features flakes eval -f '<nixpkgs>' --raw 'awscli')/share/zsh/site-functions/aws_zsh_completer.sh

For what it's worth, if you're trying to set up your shell initialization to reference nix packages, the workaround I'm using at the moment is to do this:

maybesource () {
    [[ -r $1 ]] && . $1

And then reference packages via the nix profile:

maybesource $NIX_PROFILE_ROOT/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  • 1
    I'm not sure if this has changed since this answer was posted, but for me I need to use eg nix eval --raw nixpkgs#awscli - note the hash instead of a period. Mar 17, 2022 at 0:41

For anyone else looking to do this in Bash with newer versions of Nix, use nix eval -f '<nixpkgs>' --raw PACKAGE.

For example, nix eval -f '<nixpkgs>' --raw firefox or nix eval -f '<nixpkgs>' --raw xorg.libX11.


I had a different problem, but this is in the top DDG results for nix store reference so I'll leave this here. My problem wasn't so much that I needed to reference a specific file from another package in my package, I just needed my package to have a rundep (buildInputs) on particular store paths so I could install it to my profile and they wouldn't be GC'd. (I was sick of constantly re-downloading paths when using nix-shell, and while nix-env -iA nixpkgs.stdenv worked, nix-env -iA nixpkgs.bash is apparently a different copy.)

Just putting the store paths into a text file in $out doesn't work, they need to be passed through builtins.storePath first:

writeTextDir "share/nix-shell-nogc" (builtins.concatStringsSep "\n" (builtins.map builtins.storePath [

Or alternatively, use path literals (doesn't build unless the paths exist, while the above method downloads them during build if necessary):

writeTextDir "share/nix-shell-nogc" ''

I don't like that I had to hardcode the paths, but it gets the job done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .