|
1 |
| -{ lib, stdenv, fetchFromGitHub, postgresql, perl, cmake, boost }: |
2 |
| - |
3 |
| -stdenv.mkDerivation rec { |
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + postgresql, |
| 6 | + perl, |
| 7 | + cmake, |
| 8 | + boost, |
| 9 | + buildEnv, |
| 10 | +}: |
| 11 | +let |
4 | 12 | pname = "pgrouting";
|
5 |
| - version = "3.4.1"; |
6 | 13 |
|
7 |
| - nativeBuildInputs = [ cmake perl ]; |
8 |
| - buildInputs = [ postgresql boost ]; |
| 14 | + # Load version configuration from external file |
| 15 | + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; |
9 | 16 |
|
10 |
| - src = fetchFromGitHub { |
11 |
| - owner = "pgRouting"; |
12 |
| - repo = pname; |
13 |
| - rev = "v${version}"; |
14 |
| - hash = "sha256-QC77AnPGpPQGEWi6JtJdiNsB2su5+aV2pKg5ImR2B0k="; |
15 |
| - }; |
| 17 | + # Filter versions compatible with current PostgreSQL version |
| 18 | + supportedVersions = lib.filterAttrs ( |
| 19 | + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql |
| 20 | + ) allVersions; |
16 | 21 |
|
17 |
| - #disable compile time warnings for incompatible pointer types only on macos and pg16 |
18 |
| - NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") |
19 |
| - "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types"; |
| 22 | + # Derived version information |
| 23 | + versions = lib.naturalSort (lib.attrNames supportedVersions); |
| 24 | + latestVersion = lib.last versions; |
| 25 | + numberOfVersions = builtins.length versions; |
| 26 | + packages = builtins.attrValues ( |
| 27 | + lib.mapAttrs (name: value: build name value.hash) supportedVersions |
| 28 | + ); |
20 | 29 |
|
21 |
| - cmakeFlags = [ |
22 |
| - "-DPOSTGRESQL_VERSION=${postgresql.version}" |
23 |
| - ] ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ |
24 |
| - "-DCMAKE_MACOSX_RPATH=ON" |
25 |
| - "-DCMAKE_SHARED_MODULE_SUFFIX=.dylib" |
26 |
| - "-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib" |
27 |
| - ]; |
| 30 | + # Build function for individual versions |
| 31 | + build = |
| 32 | + version: hash: |
| 33 | + stdenv.mkDerivation rec { |
| 34 | + inherit pname version; |
28 | 35 |
|
29 |
| - preConfigure = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") '' |
30 |
| - export DLSUFFIX=.dylib |
31 |
| - export CMAKE_SHARED_LIBRARY_SUFFIX=.dylib |
32 |
| - export CMAKE_SHARED_MODULE_SUFFIX=.dylib |
33 |
| - export MACOSX_RPATH=ON |
34 |
| - ''; |
| 36 | + nativeBuildInputs = [ |
| 37 | + cmake |
| 38 | + perl |
| 39 | + ]; |
| 40 | + buildInputs = [ |
| 41 | + postgresql |
| 42 | + boost |
| 43 | + ]; |
35 | 44 |
|
36 |
| - postBuild = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") '' |
37 |
| - shopt -s nullglob |
38 |
| - for file in lib/libpgrouting-*.so; do |
39 |
| - if [ -f "$file" ]; then |
40 |
| - mv "$file" "''${file%.so}.dylib" |
41 |
| - fi |
42 |
| - done |
43 |
| - shopt -u nullglob |
44 |
| - ''; |
| 45 | + src = fetchFromGitHub { |
| 46 | + owner = "pgRouting"; |
| 47 | + repo = pname; |
| 48 | + rev = "v${version}"; |
| 49 | + inherit hash; |
| 50 | + }; |
| 51 | + |
| 52 | + #disable compile time warnings for incompatible pointer types only on macos and pg16 |
| 53 | + NIX_CFLAGS_COMPILE = lib.optionalString ( |
| 54 | + stdenv.isDarwin && lib.versionAtLeast postgresql.version "16" |
| 55 | + ) "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types"; |
| 56 | + |
| 57 | + cmakeFlags = |
| 58 | + [ |
| 59 | + "-DPOSTGRESQL_VERSION=${postgresql.version}" |
| 60 | + ] |
| 61 | + ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ |
| 62 | + "-DCMAKE_MACOSX_RPATH=ON" |
| 63 | + "-DCMAKE_SHARED_MODULE_SUFFIX=.dylib" |
| 64 | + "-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib" |
| 65 | + ]; |
| 66 | + |
| 67 | + preConfigure = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") '' |
| 68 | + export DLSUFFIX=.dylib |
| 69 | + export CMAKE_SHARED_LIBRARY_SUFFIX=.dylib |
| 70 | + export CMAKE_SHARED_MODULE_SUFFIX=.dylib |
| 71 | + export MACOSX_RPATH=ON |
| 72 | + ''; |
| 73 | + |
| 74 | + postBuild = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") '' |
| 75 | + shopt -s nullglob |
| 76 | + for file in lib/libpgrouting-*.so; do |
| 77 | + if [ -f "$file" ]; then |
| 78 | + mv "$file" "''${file%.so}.dylib" |
| 79 | + fi |
| 80 | + done |
| 81 | + shopt -u nullglob |
| 82 | + ''; |
| 83 | + |
| 84 | + installPhase = '' |
| 85 | + MAJ_MIN_VERSION=${lib.concatStringsSep "." (lib.take 2 (builtins.splitVersion version))} |
| 86 | +
|
| 87 | + mkdir -p $out/{lib,share/postgresql/extension} |
| 88 | +
|
| 89 | + # Install shared library with version suffix |
| 90 | + install -D lib/libpgrouting-$MAJ_MIN_VERSION${postgresql.dlSuffix} -t $out/lib |
| 91 | +
|
| 92 | + # Create version-specific control file |
| 93 | + sed -e "/^default_version =/d" \ |
| 94 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/lib${pname}-$MAJ_MIN_VERSION'|" \ |
| 95 | + sql/common/${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control |
| 96 | +
|
| 97 | + # Copy SQL upgrade scripts |
| 98 | + cp sql/${pname}--*.sql $out/share/postgresql/extension |
| 99 | +
|
| 100 | + if [[ "${version}" == "${latestVersion}" ]]; then |
| 101 | + { |
| 102 | + echo "default_version = '${version}'" |
| 103 | + cat $out/share/postgresql/extension/${pname}--${version}.control |
| 104 | + } > $out/share/postgresql/extension/${pname}.control |
| 105 | + ln -sfn $out/lib/lib${pname}-$MAJ_MIN_VERSION${postgresql.dlSuffix} $out/lib/lib${pname}${postgresql.dlSuffix} |
| 106 | + fi |
| 107 | + ''; |
| 108 | + |
| 109 | + meta = with lib; { |
| 110 | + description = "A PostgreSQL/PostGIS extension that provides geospatial routing functionality"; |
| 111 | + homepage = "https://pgrouting.org/"; |
| 112 | + changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}"; |
| 113 | + license = licenses.gpl2Plus; |
| 114 | + inherit (postgresql.meta) platforms; |
| 115 | + }; |
| 116 | + }; |
| 117 | +in |
| 118 | +buildEnv { |
| 119 | + name = pname; |
| 120 | + paths = packages; |
| 121 | + |
| 122 | + pathsToLink = [ |
| 123 | + "/lib" |
| 124 | + "/share/postgresql/extension" |
| 125 | + ]; |
| 126 | + |
| 127 | + postBuild = '' |
| 128 | + #Verify all expected library files are present |
| 129 | + expectedFiles=${toString (numberOfVersions + 1)} |
| 130 | + actualFiles=$(ls -l $out/lib/lib${pname}*${postgresql.dlSuffix} | wc -l) |
45 | 131 |
|
46 |
| - installPhase = '' |
47 |
| - install -D lib/*${postgresql.dlSuffix} -t $out/lib |
48 |
| - install -D sql/pgrouting--*.sql -t $out/share/postgresql/extension |
49 |
| - install -D sql/common/pgrouting.control -t $out/share/postgresql/extension |
| 132 | + if [[ "$actualFiles" != "$expectedFiles" ]]; then |
| 133 | + echo "Error: Expected $expectedFiles library files, found $actualFiles" |
| 134 | + echo "Files found:" |
| 135 | + ls -la $out/lib/*${postgresql.dlSuffix} || true |
| 136 | + exit 1 |
| 137 | + fi |
50 | 138 | '';
|
51 | 139 |
|
52 |
| - meta = with lib; { |
53 |
| - description = "A PostgreSQL/PostGIS extension that provides geospatial routing functionality"; |
54 |
| - homepage = "https://pgrouting.org/"; |
55 |
| - changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}"; |
56 |
| - platforms = postgresql.meta.platforms; |
57 |
| - license = licenses.gpl2Plus; |
| 140 | + passthru = { |
| 141 | + inherit versions numberOfVersions; |
| 142 | + pname = "${pname}-all"; |
| 143 | + version = |
| 144 | + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
58 | 145 | };
|
59 | 146 | }
|
0 commit comments