pkgsStatic: error trying to link to -lzlib.a

I’m trying to make one of my maintained packages ready for static compilation. It’s a project built with meson, and I’m getting this weird error message:

> /nix/store/z3f96scg3kd3l3pk38d51wsw0axryn6x-x86_64-unknown-linux-musl-binutils-2.41/bin/x86_64-unknown-linux-musl-ld: cannot find -l/nix/store/d328kn0fnksm9bwd3wzjw0gw2471r0ca-zlib-static-x86_64-unknown-linux-musl-1.3.1/lib/libz.a: No such file or directory

So it seems it’s trying to link a file called -l/bla/libz.a, instead of libz.a. Of course, -lbla doesn’t exist, it’s obviously the wrong path. I’m a little lost on how to get to the bottom of this, however. My default.nix for the package is fairly simple I would say. I put zlib in the buildInputs, and specify no special flags to meson otherwise.

CrystFEL simply uses dependency('zlib') to find zlib (see its and then uses it later as an argument to dependencies: [...] (see here).

Where does this path mixup come from, if there’s nothing special about the handling of zlib here? Are there ways to find out how zlib is being searched for and integrated into the linker command line?

If you want to try this out, simple clone my nixpkgs repo at the crystfel-static branch and type nix-build -A pkgsStatic.crystfel-headless

You can use the --keep-failed option to inspect artifacts created in the build sandbox.

With this, you can then take a look at mesons log file at /tmp/nix-build-crystfel-static-x86_64-unknown-linux-musl-0.11.0.drv-0/crystfel-0.11.0/build/meson-logs/meson-log.txt. In there you will find that the bad option is provided by hdf5, not zlib.

The culprit is a broken hdf5.pc, which contains the line

Libs.private:  -lhdf5  -lm -ldl -l/nix/store/d328kn0fnksm9bwd3wzjw0gw2471r0ca-zlib-static-x86_64-unknown-linux-musl-1.3.1/lib/libz.a

Thank you @tobim, that was perfectly helpful! I tried patching hdf5, but failed because the project is a bit too complicated for me, but I managed to remove the faulty -l line from the pc file at least and can continue my endeavour!