Skip to content

Commit 4b9760b

Browse files
committed
fix: postgis switch-ext script
1 parent 319ea5c commit 4b9760b

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

nix/ext/postgis.nix

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
nixosTests,
1717
callPackage,
1818
buildEnv,
19+
makeWrapper,
20+
switch-ext-version,
21+
writeShellApplication,
22+
coreutils,
1923
sfcgal,
2024
latestOnly ? false,
2125
}:
@@ -44,6 +48,40 @@ let
4448
numberOfVersionsBuilt = builtins.length versionsBuilt;
4549
packages = builtins.attrValues (lib.mapAttrs (name: value: build name value.hash) versionsToUse);
4650

51+
# Custom switch script for postgis — handles all sub-libraries with -3 naming.
52+
# The generic switch-ext-version handles the main postgis library (postgis.so -> postgis-VERSION.so)
53+
# and control file. This EXTRA_STEPS script handles the -3 symlink plus the 4 additional sub-libraries.
54+
postgis-switch-extra-steps = writeShellApplication {
55+
name = "postgis-switch-extra-steps";
56+
runtimeInputs = [ coreutils ];
57+
text = ''
58+
EXT_WRAPPER_LIB="$EXT_WRAPPER/lib"
59+
CONTROL_DIR="$EXT_WRAPPER/share/postgresql/extension"
60+
61+
# Repoint the postgis-3 symlink (module_pathname uses $libdir/postgis-3)
62+
if [ -f "$EXT_WRAPPER_LIB/postgis-''${VERSION}${postgresql.dlSuffix}" ]; then
63+
ln -sfnv "postgis-''${VERSION}${postgresql.dlSuffix}" "$EXT_WRAPPER_LIB/postgis-3${postgresql.dlSuffix}"
64+
fi
65+
66+
# Switch additional sub-libraries
67+
for ext in postgis_raster postgis_topology postgis_sfcgal address_standardizer; do
68+
VERSIONED_LIB="$EXT_WRAPPER_LIB/$ext-''${VERSION}${postgresql.dlSuffix}"
69+
DEFAULT_LIB="$EXT_WRAPPER_LIB/$ext-3${postgresql.dlSuffix}"
70+
if [ -f "$VERSIONED_LIB" ]; then
71+
ln -sfnv "$VERSIONED_LIB" "$DEFAULT_LIB"
72+
73+
# Update control file for this sub-extension
74+
if [ -f "$CONTROL_DIR/$ext--''${VERSION}.control" ]; then
75+
echo "default_version = '$VERSION'" > "$CONTROL_DIR/$ext.control"
76+
cat "$CONTROL_DIR/$ext--''${VERSION}.control" >> "$CONTROL_DIR/$ext.control"
77+
fi
78+
else
79+
echo "Warning: $ext versioned library not found at $VERSIONED_LIB, skipping"
80+
fi
81+
done
82+
'';
83+
};
84+
4785
# List of C extensions to be included in the build
4886
cExtensions = [
4987
"address_standardizer"
@@ -188,7 +226,7 @@ in
188226
(buildEnv {
189227
name = pname;
190228
paths = packages;
191-
229+
nativeBuildInputs = [ makeWrapper ];
192230
pathsToLink = [
193231
"/lib"
194232
"/share/postgresql/extension"
@@ -207,6 +245,14 @@ in
207245
ls -la $out/lib/*${postgresql.dlSuffix} || true
208246
exit 1
209247
fi
248+
249+
# PostGIS has multiple sub-libraries (postgis-3, postgis_raster-3, etc.).
250+
# The generic switch-ext-version handles the main postgis.so symlink and control file.
251+
# EXTRA_STEPS repoints the -3 symlinks and switches the 4 additional sub-libraries.
252+
makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_${pname}_version \
253+
--prefix EXT_WRAPPER : "$out" \
254+
--prefix EXT_NAME : "${pname}" \
255+
--prefix EXTRA_STEPS : "${lib.getExe postgis-switch-extra-steps}"
210256
'';
211257

212258
passthru = {

0 commit comments

Comments
 (0)