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:


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

% realpath $(which 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/";

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/"

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.


1 Like