How can I find the path for this file in a package?

In the oci-cli (Oracle Cloud CLI) package there is a file which I want to source in bash/zsh shell configuration. This is the current path in the unstable ‘oci-cli’ package:

/nix/store/wvjna13dc85cc54a8pjisy5x1l5g0z9g-oci-cli-3.14.0/lib/python3.10/site-packages/oci_cli/bin/oci_autocomplete.sh

I can’t use realpath and which with the package executable, as this is the result:

% realpath $(which oci)
/nix/store/wvjna13dc85cc54a8pjisy5x1l5g0z9g-oci-cli-3.14.0/bin/oci

I can’t do text manipulation to cut the last two path components and add the rest, as the version of python will change.

I hope I have explained this well enough. I still have a lot to find out regarding nix, so I don’t know if there is a way that this can be done.

I’m pretty new to nix also, but I will try and help…

Are you using NixOS, or just the nix package manager? If you’re using NixOS, I’d suggest handling everything in your configuration.nix. In particular, you could use home-manager to add the relevant line to your bashrc.

home-manager.users.<your-username>.programs.bash = {
      enable = true;
      bashrcExtra = "source ${pkgs.oci-cli}/lib/python3.10/site-packages/oci_cli/bin/oci_autocomplete.sh";
}

Or replace bashrcExtra with profileExtra to source on login.

If home-manager isn’t an option, couldn’t you just use:
source "$(realpath $(which oci))/../../lib/python3.10/site-packages/oci_cli/bin/oci_autocomplete.sh"

Maybe I’m missing something. What do you mean about the python version changing? If you just mean you don’t know ahead of time what the python version will be, I wouldn’t expect it to change very often. If you’re worried it will go up to python3.11, you could simply source both paths, python3.10 and python 3.11, with a 2> /dev/null at the end of each command. Or if you’re feeling less lazy, write some code to check which version exists.

2 Likes

https://nixos.org/manual/nixpkgs/stable/#attributes-on-interpreters-packages

1 Like