Skip to content

Commit 4acae73

Browse files
committed
chore: wip attempt to fix search paths for postgis_tiger_geocoder
1 parent 80161e4 commit 4acae73

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

nix/ext/postgis.nix

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ stdenv.mkDerivation rec {
3535
nativeBuildInputs = [ perl pkg-config ];
3636
dontDisableStatic = true;
3737

38-
# postgis config directory assumes /include /lib from the same root for json-c library
39-
env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";
38+
# Copy our SQL file into the source
39+
postUnpack = ''
40+
cp ${./tiger_search_path.sql} $sourceRoot/tiger_search_path.sql
41+
'';
4042

43+
env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";
4144

4245
preConfigure = ''
4346
sed -i 's@/usr/bin/file@${file}/bin/file@' configure
4447
configureFlags="--datadir=$out/share/postgresql --datarootdir=$out/share/postgresql --bindir=$out/bin --docdir=$doc/share/doc/${pname} --with-gdalconfig=${gdal}/bin/gdal-config --with-jsondir=${json_c.dev} --disable-extension-upgrades-install --with-sfcgal"
4548
4649
makeFlags="PERL=${perl}/bin/perl datadir=$out/share/postgresql pkglibdir=$out/lib bindir=$out/bin docdir=$doc/share/doc/${pname}"
4750
'';
51+
4852
postConfigure = ''
4953
sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ;
5054
s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g
@@ -54,28 +58,33 @@ stdenv.mkDerivation rec {
5458
" \
5559
"raster/scripts/python/Makefile";
5660
mkdir -p $out/bin
57-
58-
# postgis' build system assumes it is being installed to the same place as postgresql, and looks
59-
# for the postgres binary relative to $PREFIX. We gently support this system using an illusion.
6061
ln -s ${postgresql}/bin/postgres $out/bin/postgres
6162
'';
6263

63-
# create aliases for all commands adding version information
64-
postInstall = ''
65-
# Teardown the illusory postgres used for building; see postConfigure.
66-
rm $out/bin/postgres
64+
postInstall = ''
65+
rm $out/bin/postgres
6766
68-
for prog in $out/bin/*; do # */
69-
ln -s $prog $prog-${version}
70-
done
67+
for prog in $out/bin/*; do # */
68+
ln -s $prog $prog-${version}
69+
done
7170
72-
for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do
73-
sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file"
74-
done
71+
# Add AddToSearchPath function to tiger_geocoder files
72+
for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do
73+
# Insert the function near the start of the file
74+
sed -i '/Copyright (C) 2010, 2011-2015 Regina Obe and Leo Hsu/r tiger_search_path.sql' "$file"
75+
76+
# Add the call to AddToSearchPath just before the install_geocode_settings function
77+
#sed -i '/CREATE FUNCTION install_geocode_settings()/i SELECT tiger.AddToSearchPath('"'"'extensions'"'"');' "$file"
78+
done
7579
76-
mkdir -p $doc/share/doc/postgis
77-
mv doc/* $doc/share/doc/postgis/
78-
'';
80+
# Original topology patching
81+
for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do
82+
sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file"
83+
done
84+
85+
mkdir -p $doc/share/doc/postgis
86+
mv doc/* $doc/share/doc/postgis/
87+
'';
7988

8089
passthru.tests.postgis = nixosTests.postgis;
8190

@@ -87,4 +96,4 @@ stdenv.mkDerivation rec {
8796
maintainers = with maintainers; [ samrose ];
8897
inherit (postgresql.meta) platforms;
8998
};
90-
}
99+
}

nix/ext/tiger_search_path.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE OR REPLACE FUNCTION tiger.AddToSearchPath(varchar)
2+
RETURNS text
3+
AS $$
4+
DECLARE
5+
var_result text;
6+
var_cur_search_path text;
7+
BEGIN
8+
-- Get current search path
9+
SELECT current_setting('search_path') INTO var_cur_search_path;
10+
11+
-- If schema is not in search path, add it
12+
IF NOT var_cur_search_path LIKE '%' || quote_ident($1) || '%' THEN
13+
var_cur_search_path := var_cur_search_path || ', ' || quote_ident($1);
14+
EXECUTE 'SET search_path = ' || quote_literal(var_cur_search_path);
15+
END IF;
16+
17+
RETURN $1 || ' added to search_path';
18+
END
19+
$$ LANGUAGE plpgsql VOLATILE STRICT SET search_path = pg_catalog;

0 commit comments

Comments
 (0)