How to find the real name (once installed) of a package

Hello, I’m a beginner with nix :slight_smile:

How to simply find the program name (pname) of a remote package ?

For example, for python37Packages.django, the package name will be Django:

$ nix-instantiate --eval -E '(import <nixpkgs> {}).python37Packages.django.pname'
"Django"

But this method does not work all the times, for example it doesn’t work for dotnetPackages.NUnitConsole:

$ nix-instantiate --eval -E '(import <nixpkgs> {}).dotnetPackages.NUnitConsole.pname'
error: attribute 'pname' missing, at (string):1:1
(use '--show-trace' to show detailed location information)

because the pname attribute seems not exist, in this case the attribute calls baseName:

$ nix-instantiate --eval -E '(import <nixpkgs> {}).dotnetPackages.NUnitConsole.baseName'
"NUnit.Console"

But one time it is installed the attribute is pname for all packages:

$ nix-env -q --json NUnit.Console-3.0.1 | jq '.[].pname'
"NUnit.Console"

Typo here.

Not every derivation has a pname. Every derivation does have name attribute though, so maybe that will work for you?

Another way is to use the web-based repo search.

Thanks I fix the type issue.

Every derivation does have name attribute though, so maybe that will work for you?

No because I need the name without the version.

I try to use nix with saltstack with custom states/modules for nix and I need to check if a package is installed from an input like dotnetPackages.NUnitConsole:

If there is no solution, I think with I could do something like this in python, get the name and version and erase the version from the name, but it is not very clean:

>>> "NUnit.Console-3.0.1".replace("-3.0.1", "")
'NUnit.Console'

It doesn’t always work but you can use builtins.parseDrvName.

nix-repl> (builtins.parseDrvName "NUnit.Console-3.0.1").name
"NUnit.Console"

Thank you for your help but it does not work :frowning:

I would like to find the real name (once package installed) from an input of nix-env and in this case I have the wrong name:

nix-repl> (builtins.parseDrvName "dotnetPackages.NUnitConsole").name
"dotnetPackages.NUnitConsole"

Pending a better solution, I change my code to question nix about name and version and I substitute version to the name:

>>> "NUnit.Console-3.0.1".replace("-3.0.1", "")
'NUnit.Console'

All derivation seems to have a name (but not a pname like you say) and a version. It works :slight_smile:

Thank you for your help :smiley:

1 Like