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