How to get a package path in /nix/store which not containing a bin dir

I want to get a path for a package which not containing a bin dir(which cannot be used for it) in current generation on NixOS.

I know nix-store -r $(which some-program) and use nix-store -q to get more info about it. But now which cannot be used because this package doesn’t have outputs with bin.

I can use ls /nix/store | grep package-name, but this will list the package in some old generations without doing a garbage collection. I only want to find the one or ones in current generation.

I find nix-env -q --out-path can print a path by only using package name or attribute but I cannot find the system-wide profiles. For example, nix-env -q print nothing. Then I try to pass something to -p option such as /etc/profiles, /nix/var/nix/profiles/system and nix/var/nix/profiles/default, but it also prints nothing.

2 Likes

nix-store -q --graph /run/current-system can find this.

I usually use fd package-name /nix/store. Fd comes from GitHub - sharkdp/fd: A simple, fast and user-friendly alternative to 'find' and is pacakged in nixpkgs.

1 Like

I have used it for some months, but it cannot solve my problem here.

nix eval <channel>.<package>.outPath
$ nix eval nixpkgs.python37.outPath
"/nix/store/4g2ilwnk4mj4g68rc52kygx7gcqxnjd0-python3-3.7.5"

NOTE: this will evalulate an outPath, given the channel (or file with --file), and may not actually exist in your store…

5 Likes

noticed your question was more about find the “system” package, in that case you could do:

$ sudo nix eval nixos.firefox.outPath
"/nix/store/vr925qf8nk6sbvk7gvks3fcplkn00nrg-firefox-69.0.2"

This may seem weird to need to do sudo, but it’s on purpose. By default, sudo/nixos subscribes to a different channel:

$ nix-channel --list
home-manager https://github.com/rycee/home-manager/archive/master.tar.gz
nixpkgs https://nixos.org/channels/nixos-unstable
$ sudo !!
sudo nix-channel --list
nixos https://nixos.org/channels/nixos-unstable

so you have to change the channel to match what channel the system is using, and then use sudo to evaluate it as root, otherwise you’ll just see your own personal/user channel.

4 Likes

Thank you! You can also add the --raw flag to avoid having to do any string munging. It excludes the surrounding quotes and the terminating newline.

1 Like

@jonringer I think the API changed, at least when I have flakes enabled, it gets confused. I ended up doing ls -1 /nix/store | grep <package-name>.

Now it would be closer to:

nix eval nixpkgs#firefox.outPath

But this assumes that nixpkgs points to the same pin of nixpkgs as what you used with your system.

5 Likes