Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.5.1.035-orioledb"
postgres17: "17.6.1.014"
postgres15: "15.14.1.014"
postgresorioledb-17: 17.5.1.036-orioledb
postgres17: 17.6.1.015
postgres15: 15.14.1.015

# Non Postgres Extensions
pgbouncer_release: 1.19.0
Expand Down
180 changes: 125 additions & 55 deletions nix/ext/pgrouting.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,139 @@
perl,
cmake,
boost,
buildEnv,
}:

stdenv.mkDerivation rec {
let
pname = "pgrouting";
version = "3.4.1";

nativeBuildInputs = [
cmake
perl
];
buildInputs = [
postgresql
boost
];
# Load version configuration from external file
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};

src = fetchFromGitHub {
owner = "pgRouting";
repo = pname;
rev = "v${version}";
hash = "sha256-QC77AnPGpPQGEWi6JtJdiNsB2su5+aV2pKg5ImR2B0k=";
};
# Filter versions compatible with current PostgreSQL version
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;

#disable compile time warnings for incompatible pointer types only on macos and pg16
NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.isDarwin && lib.versionAtLeast postgresql.version "16"
) "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types";

cmakeFlags =
[ "-DPOSTGRESQL_VERSION=${postgresql.version}" ]
++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [
"-DCMAKE_MACOSX_RPATH=ON"
"-DCMAKE_SHARED_MODULE_SUFFIX=.dylib"
"-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib"
];

preConfigure = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") ''
export DLSUFFIX=.dylib
export CMAKE_SHARED_LIBRARY_SUFFIX=.dylib
export CMAKE_SHARED_MODULE_SUFFIX=.dylib
export MACOSX_RPATH=ON
'';
# Derived version information
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
numberOfVersions = builtins.length versions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash) supportedVersions
);

postBuild = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") ''
shopt -s nullglob
for file in lib/libpgrouting-*.so; do
if [ -f "$file" ]; then
mv "$file" "''${file%.so}.dylib"
fi
done
shopt -u nullglob
'';
# Build function for individual versions
build =
version: hash:
stdenv.mkDerivation rec {
inherit pname version;

nativeBuildInputs = [
cmake
perl
];
buildInputs = [
postgresql
boost
];

src = fetchFromGitHub {
owner = "pgRouting";
repo = pname;
rev = "v${version}";
inherit hash;
};

#disable compile time warnings for incompatible pointer types only on macos and pg16
NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.isDarwin && lib.versionAtLeast postgresql.version "16"
) "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types";

cmakeFlags =
[ "-DPOSTGRESQL_VERSION=${postgresql.version}" ]
++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [
"-DCMAKE_MACOSX_RPATH=ON"
"-DCMAKE_SHARED_MODULE_SUFFIX=.dylib"
"-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib"
];

preConfigure = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") ''
export DLSUFFIX=.dylib
export CMAKE_SHARED_LIBRARY_SUFFIX=.dylib
export CMAKE_SHARED_MODULE_SUFFIX=.dylib
export MACOSX_RPATH=ON
'';

postBuild = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") ''
shopt -s nullglob
for file in lib/libpgrouting-*.so; do
if [ -f "$file" ]; then
mv "$file" "''${file%.so}.dylib"
fi
done
shopt -u nullglob
'';

installPhase = ''
MAJ_MIN_VERSION=${lib.concatStringsSep "." (lib.take 2 (builtins.splitVersion version))}

mkdir -p $out/{lib,share/postgresql/extension}

# Install shared library with version suffix
install -D lib/libpgrouting-$MAJ_MIN_VERSION${postgresql.dlSuffix} -t $out/lib

# Create version-specific control file
sed -e "/^default_version =/d" \
-e "s|^module_pathname = .*|module_pathname = '\$libdir/lib${pname}-$MAJ_MIN_VERSION'|" \
sql/common/${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control

# Copy SQL upgrade scripts
cp sql/${pname}--*.sql $out/share/postgresql/extension

if [[ "${version}" == "${latestVersion}" ]]; then
{
echo "default_version = '${version}'"
cat $out/share/postgresql/extension/${pname}--${version}.control
} > $out/share/postgresql/extension/${pname}.control
ln -sfn $out/lib/lib${pname}-$MAJ_MIN_VERSION${postgresql.dlSuffix} $out/lib/lib${pname}${postgresql.dlSuffix}
fi
'';

meta = with lib; {
description = "A PostgreSQL/PostGIS extension that provides geospatial routing functionality";
homepage = "https://pgrouting.org/";
changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}";
license = licenses.gpl2Plus;
inherit (postgresql.meta) platforms;
};
};
in
buildEnv {
name = pname;
paths = packages;

pathsToLink = [
"/lib"
"/share/postgresql/extension"
];

postBuild = ''
#Verify all expected library files are present
expectedFiles=${toString (numberOfVersions + 1)}
actualFiles=$(ls -l $out/lib/lib${pname}*${postgresql.dlSuffix} | wc -l)

installPhase = ''
install -D lib/*${postgresql.dlSuffix} -t $out/lib
install -D sql/pgrouting--*.sql -t $out/share/postgresql/extension
install -D sql/common/pgrouting.control -t $out/share/postgresql/extension
if [[ "$actualFiles" != "$expectedFiles" ]]; then
echo "Error: Expected $expectedFiles library files, found $actualFiles"
echo "Files found:"
ls -la $out/lib/*${postgresql.dlSuffix} || true
exit 1
fi
'';

meta = with lib; {
description = "A PostgreSQL/PostGIS extension that provides geospatial routing functionality";
homepage = "https://pgrouting.org/";
changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}";
platforms = postgresql.meta.platforms;
license = licenses.gpl2Plus;
passthru = {
inherit versions numberOfVersions;
pname = "${pname}-all";
version =
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
Loading