There seems to be a flaw or undocumented behavior in stacks NIX integration, more specific config.yaml.
packages: [zlib.dev, zlib.out, pcre, xdg_utils]
Stack config.yaml (or integration into NIX) seems to have problems with ‘-’ chars, so package name xdg-utils needs to be renamed xdg_utils. Is this the indented behavior? Where to find the proper package name in advance? Is this a pattern one should know?
What is the error you get?
When I use
packages: [zlib.dev, zlib.out, pcre, xdg-utils]
I get the error
└─▪ stack build
error: undefined variable ‘xdg-utils’ at (string):1:66
(use ‘–show-trace’ to show detailed location information)
even when packet is called: xdg-utils-1.1.3
using xdg_utils works
Using xdg_utils fixes another failure of stack:
when trying to open the browser after building docs I always got
stack haddock --open
… xdg-open: command not found
when using stack out of the box under nix. Now with adding xdg_utils to packages it works
The nixpkgs package name for xdg-utils IS xdg_utils, so I am not sure this is a bug
This is indeed intended behavior as the proper name to refer to the package is
The package has attribute path
xdg_utils, which identifies this package within Nixpkgs. The name
xdg-utils-1.1.3 is merely a used in the file names as a suggestion. Many different packages can share the same name, finding a package with a certain name, and most tools do not care about it. (There’s some legacy behavior in
nix-env, which I’ll not get into.)
I’m not sure where you got the name
xdg-utils from, but searching it on search.nixos.org gives this result here: https://search.nixos.org/packages?channel=20.09&query=xdg-utils, which clearly shows the name
xdg_utils, which is what you should use for almost all intents and purposes.
If you use
nix search xdg-utils you will see it that it is to be referred to as
nixpkgs.xdg_utils as well. Stack will add
nixpkgs. (basically) for you so you will only have to write
Great, Thanks a lot, for the precise and quick answer. Now I know where to get the name from.
That this fixed as well stack error not be able to start browser, missing xdg-open. Now I know I need to add
xdg_utils to packages. Could not find this in any documentation.
BTW: I got the name from nix-env -q:
nix-env -q --json xdg-utils
The issue is that the package name is “xdg-utils”. But the attribute path is “xdg_utils”.
The package name is specified in the package recipe itself. This is what is used by
nix-env -i xdg-utils for example.
And the attribute name can be found in pkgs/top-level/all-packages.nix most of the time. This is what is used by
nix-env -iA xdg_utils for example.
Unfortunately, nixpkgs doesn’t enforce a 1:1 mapping between both names which leads to that kind of confusion.
Thanks a lot for the answer:
└─▪ nix-env -qaP | grep xdg-utils
I get the translating, even from the shell. Very helpful.
Thanks to siraben, the package will be named more conveniently soon: https://github.com/NixOS/nixpkgs/pull/111519
It’s kind of surprising that you’re missing
xdg-open in your environment, as it is a standard utility for Linux desktop environments. You might want to consider reporting this to Stack if you think the error message is confusing.