at 25.11-pre 180 lines 4.3 kB view raw
1{ 2 autoconf, 3 automake, 4 cunit, 5 docbook5, 6 fetchFromGitHub, 7 fetchpatch, 8 gdalMinimal, 9 geos, 10 jitSupport, 11 json_c, 12 lib, 13 libiconv, 14 libtool, 15 libxml2, 16 libxslt, 17 llvm, 18 pcre2, 19 perl, 20 pkg-config, 21 postgresql, 22 postgresqlBuildExtension, 23 postgresqlTestExtension, 24 postgresqlTestHook, 25 proj, 26 protobufc, 27 stdenv, 28 which, 29 30 withSfcgal ? false, 31 sfcgal, 32}: 33 34let 35 gdal = gdalMinimal; 36in 37postgresqlBuildExtension (finalAttrs: { 38 pname = "postgis"; 39 version = "3.5.2"; 40 41 outputs = [ 42 "out" 43 "doc" 44 ]; 45 46 src = fetchFromGitHub { 47 owner = "postgis"; 48 repo = "postgis"; 49 tag = finalAttrs.version; 50 hash = "sha256-1kOLtG6AMavbWQ1lHG2ABuvIcyTYhgcbjuVmqMR4X+g="; 51 }; 52 53 patches = [ 54 # Backport patch for compatibility with GDAL 3.11 55 # FIXME: remove in next update 56 (fetchpatch { 57 url = "https://git.osgeo.org/gitea/postgis/postgis/commit/614eca7c169cd6e9819801d3ea99d5258262c58b.patch"; 58 hash = "sha256-VkNZFANAt8Jv+ExCusGvi+ZWB7XLcAheefSx7akA7Go="; 59 }) 60 ]; 61 62 buildInputs = 63 [ 64 geos 65 proj 66 gdal 67 json_c 68 protobufc 69 pcre2.dev 70 ] 71 ++ lib.optional stdenv.hostPlatform.isDarwin libiconv 72 ++ lib.optional withSfcgal sfcgal; 73 74 nativeBuildInputs = [ 75 autoconf 76 automake 77 libtool 78 libxml2 79 perl 80 pkg-config 81 protobufc 82 which 83 ] ++ lib.optional jitSupport llvm; 84 85 dontDisableStatic = true; 86 87 nativeCheckInputs = [ 88 postgresql 89 postgresqlTestHook 90 cunit 91 libxslt 92 ]; 93 94 postgresqlTestUserOptions = "LOGIN SUPERUSER"; 95 96 # postgis config directory assumes /include /lib from the same root for json-c library 97 env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib"; 98 99 setOutputFlags = false; 100 preConfigure = '' 101 ./autogen.sh 102 ''; 103 104 configureFlags = [ 105 "--with-pgconfig=${postgresql.pg_config}/bin/pg_config" 106 "--with-gdalconfig=${gdal}/bin/gdal-config" 107 "--with-jsondir=${json_c.dev}" 108 "--disable-extension-upgrades-install" 109 ] ++ lib.optional withSfcgal "--with-sfcgal=${sfcgal}/bin/sfcgal-config"; 110 111 makeFlags = [ 112 "PERL=${perl}/bin/perl" 113 ]; 114 115 doCheck = stdenv.hostPlatform.isLinux; 116 117 preCheck = '' 118 substituteInPlace doc/postgis-out.xml --replace-fail "http://docbook.org/xml/5.0/dtd/docbook.dtd" "${docbook5}/xml/dtd/docbook/docbookx.dtd" 119 # The test suite hardcodes it to use /tmp. 120 export PGIS_REG_TMPDIR="$TMPDIR/pgis_reg" 121 ''; 122 123 # create aliases for all commands adding version information 124 postInstall = '' 125 for prog in $out/bin/*; do # */ 126 ln -s $prog $prog-${finalAttrs.version} 127 done 128 129 mkdir -p $doc/share/doc/postgis 130 mv doc/* $doc/share/doc/postgis/ 131 ''; 132 133 passthru.tests.extension = postgresqlTestExtension { 134 inherit (finalAttrs) finalPackage; 135 sql = 136 '' 137 CREATE EXTENSION postgis; 138 CREATE EXTENSION postgis_raster; 139 CREATE EXTENSION postgis_topology; 140 -- st_makepoint goes through c code 141 select st_makepoint(1, 1); 142 '' 143 + lib.optionalString withSfcgal '' 144 CREATE EXTENSION postgis_sfcgal; 145 CREATE TABLE geometries ( 146 name varchar, 147 geom geometry(PolygonZ) NOT NULL 148 ); 149 150 INSERT INTO geometries(name, geom) VALUES 151 ('planar geom', 'PolygonZ((1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0))'), 152 ('nonplanar geom', 'PolygonZ((1 1 1, 1 2 -1, 2 2 2, 2 1 0, 1 1 1))'); 153 154 SELECT name from geometries where cg_isplanar(geom); 155 ''; 156 asserts = 157 [ 158 { 159 query = "postgis_version()"; 160 expected = "'${lib.versions.major finalAttrs.version}.${lib.versions.minor finalAttrs.version} USE_GEOS=1 USE_PROJ=1 USE_STATS=1'"; 161 description = "postgis_version() returns correct values."; 162 } 163 ] 164 ++ lib.optional withSfcgal { 165 query = "postgis_sfcgal_version()"; 166 expected = "'${sfcgal.version}'"; 167 description = "postgis_sfcgal_version() returns correct value."; 168 }; 169 }; 170 171 meta = { 172 description = "Geographic Objects for PostgreSQL"; 173 homepage = "https://postgis.net/"; 174 changelog = "https://git.osgeo.org/gitea/postgis/postgis/raw/tag/${finalAttrs.version}/NEWS"; 175 license = lib.licenses.gpl2Plus; 176 maintainers = with lib.maintainers; [ marcweber ]; 177 teams = [ lib.teams.geospatial ]; 178 inherit (postgresql.meta) platforms; 179 }; 180})