1{ fetchurl
2, lib, stdenv
3, perl
4, libxml2
5, postgresql
6, geos
7, proj
8, gdal
9, json_c
10, pkg-config
11, file
12, protobufc
13, libiconv
14, nixosTests
15}:
16stdenv.mkDerivation rec {
17 pname = "postgis";
18 version = "3.3.2";
19
20 outputs = [ "out" "doc" ];
21
22 src = fetchurl {
23 url = "https://download.osgeo.org/postgis/source/postgis-${version}.tar.gz";
24 sha256 = "sha256-miohnaAFoXMKOdGVmhx87GGbHvsAm2W+gP/CW60pkGg=";
25 };
26
27 buildInputs = [ libxml2 postgresql geos proj gdal json_c protobufc ]
28 ++ lib.optional stdenv.isDarwin libiconv;
29 nativeBuildInputs = [ perl pkg-config ] ++ lib.optional postgresql.jitSupport postgresql.llvm;
30 dontDisableStatic = true;
31
32 # postgis config directory assumes /include /lib from the same root for json-c library
33 NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";
34
35 preConfigure = ''
36 sed -i 's@/usr/bin/file@${file}/bin/file@' configure
37 configureFlags="--datadir=$out/share/postgresql --datarootdir=$out/share/postgresql --bindir=$out/bin --with-gdalconfig=${gdal}/bin/gdal-config --with-jsondir=${json_c.dev}"
38
39 makeFlags="PERL=${perl}/bin/perl datadir=$out/share/postgresql pkglibdir=$out/lib bindir=$out/bin"
40 '';
41 postConfigure = ''
42 sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ;
43 s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
44 " \
45 "raster/loader/Makefile";
46 sed -i "s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
47 " \
48 "raster/scripts/python/Makefile";
49 mkdir -p $out/bin
50
51 # postgis' build system assumes it is being installed to the same place as postgresql, and looks
52 # for the postgres binary relative to $PREFIX. We gently support this system using an illusion.
53 ln -s ${postgresql}/bin/postgres $out/bin/postgres
54 '';
55
56 # create aliases for all commands adding version information
57 postInstall = ''
58 # Teardown the illusory postgres used for building; see postConfigure.
59 rm $out/bin/postgres
60
61 for prog in $out/bin/*; do # */
62 ln -s $prog $prog-${version}
63 done
64
65 mkdir -p $doc/share/doc/postgis
66 mv doc/* $doc/share/doc/postgis/
67 '';
68
69 passthru.tests.postgis = nixosTests.postgis;
70
71 meta = with lib; {
72 description = "Geographic Objects for PostgreSQL";
73 homepage = "https://postgis.net/";
74 changelog = "https://git.osgeo.org/gitea/postgis/postgis/raw/tag/${version}/NEWS";
75 license = licenses.gpl2;
76 maintainers = [ maintainers.marcweber ];
77 inherit (postgresql.meta) platforms;
78 };
79}