Hello, I’m a beginner with nix
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"
ryantm
April 10, 2020, 9:03pm
2
gigi206:
pame
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 :
chan = name.split(".")[0]
pkg = ".".join(name.split(".")[1:])
else:
ret["result"] = False
ret[
"comment"
] = "Package name must respect this form: <channel>.<pkg> (example: nixpkgs.vscode)"
return ret
cmd_pkg_name = __salt__["cmd.run_all"](
"nix-instantiate --eval -E '(import <{}> {{}}).{}.pname'".format(chan, pkg),
python_shell=True,
)
if cmd_pkg_name["retcode"] == 0:
pkg_name = cmd_pkg_name["stdout"].strip('"')
else:
ret["result"] = False
ret["comment"] = "Package {} not found".format(name)
return ret
else:
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'
ryantm
April 11, 2020, 12:21am
5
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
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
Thank you for your help
1 Like