Pkg-config, pkgconfig and python

I’m trying to make an expression for python-xmlsec, and in the build phase, when it tried to build the python extension, pkgconfig complains that it cannot find the library xmlsec.

Which surprises me a bit, because adding:

  preBuild = ''
    pkg-config --variable=prefix xmlsec1
    python -c "import pkgconfig;  pkgconfig.parse('xmlsec1')"
  '';

shows that pkg-config finds it alright, but python doesn’t. (I was also surprised that I have to add pkg-config specifically to the inputs, because otherwise pkgconfig doesn’t seem to see it.)

This is the expression after several tries with native, propagate, .dev, … Forgive the messy state.

Any pointers?

{ lib, pkgs,
  fetchPypi,  setuptools_scm,  buildPythonPackage,  cython,
  toml,  lxml,  pkgconfig
}:

buildPythonPackage rec {
  pname = "py-xmlsec";
  version = "1.3.8";

  src = fetchPypi {
    inherit version;
    pname="xmlsec";
    sha256 = "1ki5jiws8r9sbdbbn5cw058m57rhx42g91rrsa2bblqwngi3z546";
  };

  nativeBuildInputs = [ pkgconfig  pkgs.xmlsec.dev pkgs.xmlsec.dev pkgs.openssl.dev setuptools_scm  cython pkgs.libxml2.dev pkgs.pkg-config];
  buildInputs = [ pkgs.xmlsec.dev pkgs.openssl lxml pkgs.xmlsec toml pkgconfig pkgs.libxml2.dev];

  preBuild = ''
    pkg-config --variable=prefix xmlsec1
    python -c "import pkgconfig;  pkgconfig.parse('xmlsec1')"
   '';
}

That’s because the xmlsec that’s packaged in nixpkgs doesn’t export a .pc, so there’s nothing for pkg-config to determine xmlsec1 settings

PR to fix this: xmlsec: 1.2.28 -> 1.2.30 by jonringer · Pull Request #99876 · NixOS/nixpkgs · GitHub

even with the fix, it still doesn’t seem to work even though:

/nix/store/v9cgm5jrf96yvimg3ihzgn8sr0p2yks3-xmlsec-1.2.30-dev/lib/pkgconfig

is in PKG_CONFIG_PATH, and:

$ tree /nix/store/v9cgm5jrf96yvimg3ihzgn8sr0p2yks3-xmlsec-1.2.30-dev/lib/pkgconfig
/nix/store/v9cgm5jrf96yvimg3ihzgn8sr0p2yks3-xmlsec-1.2.30-dev/lib/pkgconfig
├── xmlsec1-gcrypt.pc
├── xmlsec1-gnutls.pc
├── xmlsec1-nss.pc
├── xmlsec1-openssl.pc
└── xmlsec1.pc

script:

with import ./. { };

pkgs.python3Packages.callPackage (
{ lib, pkgs,
  fetchPypi,  setuptools_scm,  buildPythonPackage,  cython,
  toml,  lxml,  pkgconfig
}:

buildPythonPackage rec {
  pname = "py-xmlsec";
  version = "1.3.8";

  src = fetchPypi {
    inherit version;
    pname="xmlsec";
    sha256 = "1ki5jiws8r9sbdbbn5cw058m57rhx42g91rrsa2bblqwngi3z546";
  };

  nativeBuildInputs = [ pkg-config pkgconfig  setuptools_scm  cython ];
  buildInputs = [ openssl lxml xmlsec toml libxml2 ];

  preBuild = ''
    set -x
    echo $PKG_CONFIG_PATH
    pkg-config --exists xmlsec1
  #  pkg-config --variable=prefix xmlsec1
  #  python -c "import pkgconfig;  pkgconfig.parse('xmlsec1')"
  '';
  })

 { }

Ah!
Why did pkg-config --variable=prefix xmlsec1 work then? :confused:

Not sure if it will work here, but I’ve used export LD_LIBRARY_PATH="${xmlsec}/lib".

I’m not sure, but pkg-config --exists xmlsec1 does fail for me.

But I’m not super familiar with pkg-config either