nixpkgs/pkgs/servers/sql/postgresql/ext/postgis.nix
Luke Worth 330fff02a6 postgis: allow on Darwin
To get PostGIS going on Darwin:
1. Add libiconv, as is often required.
2. Expand platforms to `platforms.all`.
3. Deal with PostGIS' quirky build system.

PostGIS' configure.ac has the following gem:

  AC_MSG_RESULT([------------------------------------------------------------------------])
  AC_MSG_RESULT([  WARNING: You have set the --prefix to '$prefix'. But we mostly    ])
  AC_MSG_RESULT([  ignore the --prefix. For your info, using the values determined from ])
  AC_MSG_RESULT([  $PG_CONFIG we will be installing:   ])
  AC_MSG_RESULT([    * postgis shared library in $PGSQL_LIBDIR ])
  AC_MSG_RESULT([    * postgis SQL files in $PGSQL_SHAREDIR/contrib/postgis-$POSTGIS_MAJOR_VERSION.$POSTGIS_MINOR_VERSION ])
  AC_MSG_RESULT([    * postgis executables in $PGSQL_BINDIR ])
  AC_MSG_RESULT([------------------------------------------------------------------------])

This is suggestive of some assumptions in the build system, which are
revealed when building in Nix on Darwin: the build fails because the
postgres binary cannot be found in the install prefix specified for
postgis; vis.

  cc x -bundle_loader $POSTGIS_PREFIX/bin/postgres

This bundle_loader parameter is only available on Darwin, and this
problem doesn't appear to affect Linux systems.

The solution presented here is to symlink the postgres binary where
PostGIS expects it to be, and then remove it after the build completes.
2019-07-27 19:00:46 +10:00

70 lines
1.9 KiB
Nix

{ fetchurl
, stdenv
, perl
, libxml2
, postgresql
, geos
, proj
, gdal
, json_c
, pkgconfig
, file
, protobufc
, libiconv
}:
stdenv.mkDerivation rec {
name = "postgis-${version}";
version = "2.5.2";
outputs = [ "out" "doc" ];
src = fetchurl {
url = "https://download.osgeo.org/postgis/source/postgis-${version}.tar.gz";
sha256 = "0pnva72f2w4jcgnl1y7nw5rdly4ipx3hji4c9yc9s0hna1n2ijxn";
};
buildInputs = [ libxml2 postgresql geos proj gdal json_c protobufc libiconv ];
nativeBuildInputs = [ perl pkgconfig ];
dontDisableStatic = true;
# postgis config directory assumes /include /lib from the same root for json-c library
NIX_LDFLAGS = "-L${stdenv.lib.getLib json_c}/lib";
preConfigure = ''
sed -i 's@/usr/bin/file@${file}/bin/file@' configure
configureFlags="--datadir=$out/share/postgresql --datarootdir=$out/share/postgresql --bindir=$out/bin --with-gdalconfig=${gdal}/bin/gdal-config --with-jsondir=${json_c.dev}"
makeFlags="PERL=${perl}/bin/perl datadir=$out/share/postgresql pkglibdir=$out/lib bindir=$out/bin"
'';
postConfigure = ''
sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ;
s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
" \
"raster/loader/Makefile";
sed -i "s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
" \
"raster/scripts/python/Makefile";
mkdir -p $out/bin
ln -s ${postgresql}/bin/postgres $out/bin/postgres
'';
# create aliases for all commands adding version information
postInstall = ''
rm $out/bin/postgres
for prog in $out/bin/*; do # */
ln -s $prog $prog-${version}
done
mkdir -p $doc/share/doc/postgis
mv doc/* $doc/share/doc/postgis/
'';
meta = with stdenv.lib; {
description = "Geographic Objects for PostgreSQL";
homepage = https://postgis.net/;
license = licenses.gpl2;
maintainers = [ maintainers.marcweber ];
platforms = platforms.all;
};
}