|
16 | 16 | nixosTests, |
17 | 17 | callPackage, |
18 | 18 | buildEnv, |
| 19 | + makeWrapper, |
| 20 | + switch-ext-version, |
| 21 | + writeShellApplication, |
| 22 | + coreutils, |
19 | 23 | sfcgal, |
20 | 24 | latestOnly ? false, |
21 | 25 | }: |
|
44 | 48 | numberOfVersionsBuilt = builtins.length versionsBuilt; |
45 | 49 | packages = builtins.attrValues (lib.mapAttrs (name: value: build name value.hash) versionsToUse); |
46 | 50 |
|
| 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 | + |
47 | 85 | # List of C extensions to be included in the build |
48 | 86 | cExtensions = [ |
49 | 87 | "address_standardizer" |
|
188 | 226 | (buildEnv { |
189 | 227 | name = pname; |
190 | 228 | paths = packages; |
191 | | - |
| 229 | + nativeBuildInputs = [ makeWrapper ]; |
192 | 230 | pathsToLink = [ |
193 | 231 | "/lib" |
194 | 232 | "/share/postgresql/extension" |
|
207 | 245 | ls -la $out/lib/*${postgresql.dlSuffix} || true |
208 | 246 | exit 1 |
209 | 247 | 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}" |
210 | 256 | ''; |
211 | 257 |
|
212 | 258 | passthru = { |
|
0 commit comments