Pkg-config and PKG_CONFIG_PATH

I have a flake with an output which contains a lib/pkgconfig/my-package.pc.

In the devShell of the same flake, I have this dubious hack

shellHook = ''
    export MY_LIB=$PWD/install/my-package/lib
    export PKG_CONFIG_PATH=$MY_LIB/pkgconfig:$PKG_CONFIG_PATH;

which allows me to turn the error

Run-time dependency my-package found: NO (tried pkgconfig)


Run-time dependency my-package found: YES v0.1.10

in a local meson-based build of something that depends on my-package.

I have a client flake which has my-package as a build input and uses it as a dependency in an output package. When I try to build the latter, we get the earlier error once more

Run-time dependency my-package found: NO (tried pkgconfig)

I get the impression that I’m missing something fundamental about how pkg-config should be used in Nix.

How should I ensure that the pkg-config information provided by my-package is found by its clients?

It turns out that my-package was missing from the (native)buildInputs of the package that depended on it.