Flaw in Nix integration of stack

There seems to be a flaw or undocumented behavior in stacks NIX integration, more specific config.yaml.

nix:
enable: true
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?

1 Like

When I use
nix:
enable: true
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

1 Like

This is indeed intended behavior as the proper name to refer to the package is xdg_utils.

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 xdg_utils.

1 Like

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.

Thanks again.

BTW: I got the name from nix-env -q:

nix-env -q --json xdg-utils
{
“0”: {
“name”: “xdg-utils-1.1.3”,
“pname”: “xdg-utils”,
“version”: “1.1.3”,
“system”: “x86_64-linux”,

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.

1 Like

Thanks a lot for the answer:

Using

└─▪ nix-env -qaP | grep xdg-utils
nixos.xdg_utils xdg-utils-unstable-2020-10-21

I get the translating, even from the shell. Very helpful.

Thanks to siraben, the package will be named more conveniently soon: treewide: xdg_utils -> xdg-utils by siraben · Pull Request #111519 · NixOS/nixpkgs · GitHub

1 Like

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.