1args@{fetchurl, composableDerivation, stdenv, perl, libxml2, postgresql, geos, proj, flex, gdal, json_c, pkgconfig, file, ...}:
2
3 /*
4
5 ### NixOS - usage:
6 ==================
7
8 services.postgresql.extraPlugins = [ (pkgs.postgis.override { postgresql = pkgs.postgresql95; }).v_2_3_1 ];
9
10
11 ### important Postgis implementation details:
12 =============================================
13
14 Postgis provides a shared library implementing many operations. They are
15 exposed to the Postgres SQL interpreter by special SQL queries eg:
16
17 CREATE FUNCTION [...]
18 AS '[..]liblwgeom', 'lwhistogram2d_in' LANGUAGE 'C' IMMUTABLE STRICT; -- WITH (isstrict);
19
20 where liblwgeom is the shared library.
21 Postgis < 1.5 used absolute paths, in NixOS $libdir is always used.
22
23 Thus if you want to use postgresql dumps which were created by non NixOS
24 systems you have to adopt the library path.
25
26
27 ### TODO:
28 =========
29 the bin commands to have gtk gui:
30 */
31
32
33let
34 pgDerivationBase = composableDerivation.composableDerivation {} ( fix :
35
36 let version = fix.fixed.version; in {
37
38 name = "postgis-${version}";
39
40 src = fetchurl {
41 url = "http://postgis.refractions.net/download/postgis-${fix.fixed.version}.tar.gz";
42 inherit (fix.fixed) sha256;
43 };
44
45 # don't pass these vars to the builder
46 removeAttrs = ["hash" "sql_comments" "sql_srcs"];
47
48 preConfigure = ''
49 configureFlags="--datadir=$out/share --datarootdir=$out/share --bindir=$out/bin"
50 makeFlags="PERL=${perl}/bin/perl datadir=$out/share pkglibdir=$out/lib bindir=$out/bin"
51 '';
52
53 # create aliases for all commands adding version information
54 postInstall = ''
55
56 sql_srcs=$(for sql in ${builtins.toString fix.fixed.sql_srcs}; do echo -n "$(find $out -iname "$sql") "; done )
57
58 for prog in $out/bin/*; do # */
59 ln -s $prog $prog-${version}
60 done
61
62 cp -r doc $out
63 '';
64
65 buildInputs = [libxml2 postgresql geos proj perl];
66
67 sql_comments = "postgis_comments.sql";
68
69 meta = {
70 description = "Geographic Objects for PostgreSQL";
71 homepage = http://postgis.refractions.net;
72 license = stdenv.lib.licenses.gpl2;
73 maintainers = [stdenv.lib.maintainers.marcweber];
74 platforms = stdenv.lib.platforms.linux;
75 };
76 });
77
78 pgDerivationBaseNewer = pgDerivationBase.merge (fix: {
79 src = fetchurl {
80 url = "http://download.osgeo.org/postgis/source/postgis-${builtins.toString fix.fixed.version}.tar.gz";
81 inherit (fix.fixed) sha256;
82 };
83 });
84
85in rec {
86
87 v_2_3_1 = pgDerivationBaseNewer.merge ( fix : {
88 version = "2.3.1";
89 sha256 = "0xd21h2k6x3i1b3z6pgm3pmkfpxm6irxd5wbx68acjndjgd6p3ac";
90 sql_srcs = ["postgis.sql" "spatial_ref_sys.sql"];
91 builtInputs = [gdal json_c pkgconfig];
92
93 # postgis config directory assumes /include /lib from the same root for json-c library
94 NIX_LDFLAGS = "-L${stdenv.lib.getLib json_c}/lib";
95
96 dontDisableStatic = true;
97 preConfigure = ''
98 sed -i 's@/usr/bin/file@${file}/bin/file@' configure
99 configureFlags="$configureFlags --with-gdalconfig=${gdal}/bin/gdal-config --with-jsondir=${json_c.dev}"
100 '';
101 postConfigure = ''
102 sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ;
103 s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
104 " \
105 "raster/loader/Makefile";
106 sed -i "s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
107 " \
108 "raster/scripts/python/Makefile";
109 '';
110 });
111
112}