Commit 631742c8 authored by Artturin's avatar Artturin
Browse files

python311Packages.psycopg2: fix cross

```nix
> /nix/store/iipxk03rab2vagl196i084b4918a65pn-aarch64-unknown-linux-gnu-binutils-2.40/bin/aarch64-unknown-linux-gnu-ld: skipping incompatible /nix/store/sk7c7f10fxn7iypqgaaq9l0s9ipkk0mc-postgresql-14.9-lib/lib/libpq.so when searching for -lpq
> /nix/store/iipxk03rab2vagl196i084b4918a65pn-aarch64-unknown-linux-gnu-binutils-2.40/bin/aarch64-unknown-linux-gnu-ld: cannot find -lpq: No such file or directory
> /nix/store/iipxk03rab2vagl196i084b4918a65pn-aarch64-unknown-linux-gnu-binutils-2.40/bin/aarch64-unknown-linux-gnu-ld: skipping incompatible /nix/store/sk7c7f10fxn7iypqgaaq9l0s9ipkk0mc-postgresql-14.9-lib/lib/libpq.so when searching for -lpq
```
parent f82f259f
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
, openssl
, sphinxHook
, sphinx-better-theme
, buildPackages
}:

buildPythonPackage rec {
@@ -19,20 +20,29 @@ buildPythonPackage rec {
  # c.f. https://github.com/NixOS/nixpkgs/pull/104151#issuecomment-729750892
  disabled = pythonOlder "3.6" || isPyPy;

  outputs = [ "out" "doc" ];

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-pSRtLmg6ly4hh6hxS1ws+BVsBkYp+amxqHPBcw2eJFo=";
  };

  outputs = [ "out" "doc" ];
  postPatch = ''
    # Preferably upstream would not depend on pg_config because config scripts are incompatible with cross-compilation, however postgresql's pc file is lacking information.
    # some linker flags are added but the linker ignores them because they're incompatible
    # https://github.com/psycopg/psycopg2/blob/89005ac5b849c6428c05660b23c5a266c96e677d/setup.py
    substituteInPlace setup.py \
      --replace "self.pg_config_exe = self.build_ext.pg_config" 'self.pg_config_exe = "${lib.getExe' buildPackages.postgresql "pg_config"}"'
  '';

  nativeBuildInputs = [
    postgresql
    sphinxHook
    sphinx-better-theme
  ];

  buildInputs = lib.optionals stdenv.isDarwin [
  buildInputs = [
    postgresql
  ] ++ lib.optionals stdenv.isDarwin [
    openssl
  ];

@@ -45,6 +55,8 @@ buildPythonPackage rec {
    "psycopg2"
  ];

  disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ buildPackages.postgresql ];

  meta = with lib; {
    description = "PostgreSQL database adapter for the Python programming language";
    homepage = "https://www.psycopg.org";