python3Packages.pymupdf: propagated mupdf-cxx in such a way that it won't be filtered out

Otherwise, we end up in this situation where this derivation works:

```nix
{ pkgs ? import ./. { } }:

pkgs.runCommand "driver" { buildInputs = [ pkgs.python3Packages.pymupdf ]; } ''
  python -c 'import pymupdf;' > $out
''
```

... but this ostensibly identical derivation fails.

```nix
{ pkgs ? import ./. { } }:

pkgs.runCommand "driver" { buildInputs = [ pkgs.python3.withPackages (ps: [ ps.pymupdf ]; } ''
  python -c 'import pymupdf;' > $out
''
```

What's happening is that the propagated input `mupdf-cxx` doesn't pass the filter check in `requiredPythonModules` as it does not have a Python module as defined in that function.

Now, it does.

Huge thanks to hexa who debugged this with me on Matrix.

Co-authored-by: Martin Weinelt <hexa@darmstadt.ccc.de>
This commit is contained in:
Philip Taron
2025-05-30 15:59:10 -07:00
co-authored by Martin Weinelt
parent bf9f4a1bcf
commit 36354c7702
@@ -6,6 +6,7 @@
fetchFromGitHub,
fetchpatch,
python,
toPythonModule,
# build-system
libclang,
@@ -39,6 +40,8 @@ let
enablePython = true;
python3 = python;
};
mupdf-cxx-lib = toPythonModule (lib.getLib mupdf-cxx);
mupdf-cxx-dev = lib.getDev mupdf-cxx;
in
buildPythonPackage rec {
pname = "pymupdf";
@@ -87,7 +90,7 @@ buildPythonPackage rec {
gumbo
];
propagatedBuildInputs = [ mupdf-cxx ];
propagatedBuildInputs = [ mupdf-cxx-lib ];
env = {
# force using system MuPDF (must be defined in environment and empty)
@@ -95,14 +98,14 @@ buildPythonPackage rec {
# Setup the name of the package away from the default 'libclang'
PYMUPDF_SETUP_LIBCLANG = "clang";
# provide MuPDF paths
PYMUPDF_MUPDF_LIB = "${lib.getLib mupdf-cxx}/lib";
PYMUPDF_MUPDF_INCLUDE = "${lib.getDev mupdf-cxx}/include";
PYMUPDF_MUPDF_LIB = "${mupdf-cxx-lib}/lib";
PYMUPDF_MUPDF_INCLUDE = "${mupdf-cxx-dev}/include";
};
# TODO: manually add mupdf rpath until upstream fixes it
postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
for lib in */*.so $out/${python.sitePackages}/*/*.so; do
install_name_tool -add_rpath ${lib.getLib mupdf-cxx}/lib "$lib"
install_name_tool -add_rpath ${mupdf-cxx-lib}/lib "$lib"
done
'';