Merge pull request #5926 from benmos/postgis

Postgis 2.1.4 support

+31 -73
+31 -73
pkgs/development/libraries/postgis/default.nix
··· 1 - args@{fetchurl, composableDerivation, stdenv, perl, libxml2, postgresql, geos, proj, flex, ...}: 2 3 /* 4 5 ### NixOS - usage: 6 ================== 7 8 - services.posgresql.extraPlugins = [ pkgs.postgis.v_1_5_1 ]; 9 - 10 - or if you want to install 1.5.x and 1.3.x at the same time (which works 11 - because the .sql and .so files have different names): 12 - 13 - services.postgis.extraPlugins = [ (pkgs.buildEnv { 14 - name = "postgis-plugins"; 15 - ignoreCollisions = 1; # scripts will collide - but there are aliases with version suffixes 16 - paths = [ pkgs.postgis.v_1_3_5 pkgs.postgis.v_1_5_1 ]; 17 - })]; 18 - 19 - By now it is only supported installing one of the 1.3.x verions because 20 - their shared libraries don't differ in naming. 21 - 22 23 24 ### important Postgis implementation details: ··· 29 30 CREATE FUNCTION [...] 31 AS '[..]liblwgeom', 'lwhistogram2d_in' LANGUAGE 'C' IMMUTABLE STRICT; -- WITH (isstrict); 32 - 33 where liblwgeom is the shared library. 34 Postgis < 1.5 used absolute paths, in NixOS $libdir is always used. 35 36 Thus if you want to use postgresql dumps which were created by non NixOS 37 systems you have to adopt the library path. 38 - 39 40 41 ### TODO: ··· 52 name = "postgis-${version}"; 53 54 src = fetchurl { 55 - url = "http://download.osgeo.org/postgis/source/postgis-${fix.fixed.version}.tar.gz"; 56 inherit (fix.fixed) sha256; 57 }; 58 ··· 64 makeFlags="PERL=${perl}/bin/perl datadir=$out/share pkglibdir=$out/lib bindir=$out/bin" 65 ''; 66 67 - pg_db_postgis_enable = ./pg_db_postgis_enable.sh; 68 - 69 - scriptNames = [ "pg_db_postgis_enable" ]; # helper scripts 70 - 71 - # prepare fixed parameters for script and create pg_db_postgis_enable script. 72 - # The script just loads postgis features into a list of given databases 73 - postgisEnableScript = '' 74 - s=$out/bin/pg_db_postgis_enable 75 - 76 - sql_comments=$out/share/postgis-${version}/comments.sql 77 - mkdir -p $(dirname $sql_comments) 78 - cp $(find -iname ${fix.fixed.sql_comments}) $sql_comments 79 - 80 - for script in $scriptNames; do 81 - tg=$out/bin/$script 82 - substituteAll ''${!script} $tg 83 - chmod +x $tg 84 - done 85 - ''; 86 - 87 - # create a script enabling postgis features 88 - # also create aliases for all commands adding version information 89 postInstall = '' 90 91 sql_srcs=$(for sql in ${builtins.toString fix.fixed.sql_srcs}; do echo -n "$(find $out -iname "$sql") "; done ) 92 93 - eval "$postgisEnableScript" 94 - eval "$postgisFixLibScript" 95 - 96 - for prog in $out/bin/*; do 97 ln -s $prog $prog-${version} 98 done 99 ··· 113 }; 114 }); 115 116 - 117 - in rec { 118 - 119 - # these builders just add some custom informaton to the receipe above 120 - 121 - v_1_3_5 = pgDerivationBase.merge ( fix: { 122 - version = "1.3.5"; 123 - buildInputs = [ flex ]; 124 - sha256 = "102d5ybn0db1wrb249dga2v8347vysd4f1brc8zb82d7vdd34wyq"; 125 - sql_srcs = ["lwpostgis.sql" "spatial_ref_sys.sql"]; 126 - 127 - pg_db_postgis_fix_or_load_sql_dump = ./pg_db_postgis_fix_or_load_sql_dump.sh; 128 - libName = "liblwgeom"; 129 - scriptNames = [ "pg_db_postgis_enable" "pg_db_postgis_fix_or_load_sql_dump"]; # helper scripts 130 - 131 - # sql_srcs is defined in postInstall source above 132 - # if store path changes sql should not break. So replace absolute path to 133 - # shared library by path relatve to $libdir known by Postgres. 134 - postInstall = '' 135 - sed -i "s@AS '$out/lib/liblwgeom@AS '\$libdir/liblwgeom@" $sql_srcs $out/share/lwpostgis_upgrade.sql 136 - ''; 137 }); 138 139 - v_1_3_6 = v_1_3_5.merge ({ 140 - version = "1.3.6"; 141 - sha256 = "0i6inyiwc5zgf5a4ssg0y774f8vn45zn5c38ccgnln9r6i54vc6k"; 142 - }); 143 144 - v_1_5_8 = pgDerivationBase.merge ( fix : { 145 - version = "1.5.8"; 146 - sha256 = "016qn2hk3w8rg60rqn91l2nfk9zcsw0pv2s5rb1qhjw15ypgv5j8"; 147 sql_srcs = ["postgis.sql" "spatial_ref_sys.sql"]; 148 }); 149 150 - }
··· 1 + args@{fetchurl, composableDerivation, stdenv, perl, libxml2, postgresql, geos, proj, flex, gdal, pkgconfig, file, ...}: 2 3 /* 4 5 ### NixOS - usage: 6 ================== 7 8 + services.postgresql.extraPlugins = [ (pkgs.postgis.override { postgresql = pkgs.postgresql94; }).v_2_1_4 ]; 9 10 11 ### important Postgis implementation details: ··· 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: ··· 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 ··· 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 ··· 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 85 + in rec { 86 87 + v_2_1_4 = pgDerivationBaseNewer.merge ( fix : { 88 + version = "2.1.4"; 89 + sha256 = "1z00n5654r7l38ydkn2grbwl5gg0mravjwxfdipp7j18hjiw4wyd"; 90 sql_srcs = ["postgis.sql" "spatial_ref_sys.sql"]; 91 + builtInputs = [gdal pkgconfig]; 92 + dontDisableStatic = true; 93 + preConfigure = '' 94 + sed -i 's@/usr/bin/file@${file}/bin/file@' configure 95 + configureFlags="$configureFlags --with-gdalconfig=${gdal}/bin/gdal-config" 96 + ''; 97 + postConfigure = '' 98 + sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ; 99 + s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g 100 + " \ 101 + "raster/loader/Makefile"; 102 + sed -i "s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g 103 + " \ 104 + "raster/scripts/python/Makefile"; 105 + ''; 106 }); 107 108 + }