nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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.6.1";
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-WVS2TWKishTnCWJ87Vvdcb0i3VR+g/qSjcTDO1cx1s0=";
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 checkInputs = [
78 cunit
79 ];
80
81 nativeCheckInputs = [
82 postgresql
83 postgresqlTestHook
84 libxslt
85 ];
86
87 postgresqlTestUserOptions = "LOGIN SUPERUSER";
88
89 # postgis config directory assumes /include /lib from the same root for json-c library
90 env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";
91
92 setOutputFlags = false;
93 preConfigure = ''
94 ./autogen.sh
95 '';
96
97 configureFlags =
98 let
99 isCross = stdenv.hostPlatform.config != stdenv.buildPlatform.config;
100 in
101 [
102 (lib.withFeatureAs true "pgconfig" "${postgresql.pg_config}/bin/pg_config")
103 (lib.withFeatureAs true "gdalconfig" "${gdal}/bin/gdal-config")
104 (lib.withFeatureAs true "jsondir" (lib.getDev json_c))
105 (lib.withFeatureAs true "xml2config" (lib.getExe' (lib.getDev libxml2) "xml2-config"))
106 (lib.withFeatureAs withSfcgal "sfcgal" "${sfcgal}/bin/sfcgal-config")
107 (lib.withFeature (!isCross) "json") # configure: error: cannot check for file existence when cross compiling
108 ];
109
110 makeFlags = [
111 "PERL=${perl}/bin/perl"
112 ];
113
114 doCheck = stdenv.hostPlatform.isLinux;
115
116 preCheck = ''
117 substituteInPlace doc/postgis-out.xml --replace-fail "http://docbook.org/xml/5.0/dtd/docbook.dtd" "${docbook5}/xml/dtd/docbook/docbookx.dtd"
118 # The test suite hardcodes it to use /tmp.
119 export PGIS_REG_TMPDIR="$TMPDIR/pgis_reg"
120 '';
121
122 # create aliases for all commands adding version information
123 postInstall = ''
124 for prog in $out/bin/*; do # */
125 ln -s $prog $prog-${finalAttrs.version}
126 done
127
128 mkdir -p $doc/share/doc/postgis
129 mv doc/* $doc/share/doc/postgis/
130 '';
131
132 passthru.tests.extension = postgresqlTestExtension {
133 inherit (finalAttrs) finalPackage;
134 sql = ''
135 CREATE EXTENSION postgis;
136 CREATE EXTENSION postgis_raster;
137 CREATE EXTENSION postgis_topology;
138 -- st_makepoint goes through c code
139 select st_makepoint(1, 1);
140 ''
141 + lib.optionalString withSfcgal ''
142 CREATE EXTENSION postgis_sfcgal;
143 CREATE TABLE geometries (
144 name varchar,
145 geom geometry(PolygonZ) NOT NULL
146 );
147
148 INSERT INTO geometries(name, geom) VALUES
149 ('planar geom', 'PolygonZ((1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0))'),
150 ('nonplanar geom', 'PolygonZ((1 1 1, 1 2 -1, 2 2 2, 2 1 0, 1 1 1))');
151
152 SELECT name from geometries where cg_isplanar(geom);
153 '';
154 asserts = [
155 {
156 query = "postgis_version()";
157 expected = "'${lib.versions.major finalAttrs.version}.${lib.versions.minor finalAttrs.version} USE_GEOS=1 USE_PROJ=1 USE_STATS=1'";
158 description = "postgis_version() returns correct values.";
159 }
160 ]
161 ++ lib.optional withSfcgal {
162 query = "postgis_sfcgal_version()";
163 expected = "'${sfcgal.version}'";
164 description = "postgis_sfcgal_version() returns correct value.";
165 };
166 };
167
168 meta = {
169 description = "Geographic Objects for PostgreSQL";
170 homepage = "https://postgis.net/";
171 changelog = "https://git.osgeo.org/postgis/postgis/raw/tag/${finalAttrs.version}/NEWS";
172 license = lib.licenses.gpl2Plus;
173 maintainers = with lib.maintainers; [ marcweber ];
174 teams = [ lib.teams.geospatial ];
175 inherit (postgresql.meta) platforms;
176 };
177})