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