Skip to content

Commit

Permalink
feat: package gdal + fix basePackages to switch pg version correctly (#…
Browse files Browse the repository at this point in the history
…1231)

Co-authored-by: Sam Rose <samuel@supabase.io>
  • Loading branch information
samrose and Sam Rose authored Sep 26, 2024
1 parent 092d970 commit 349cc83
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 25 deletions.
41 changes: 32 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
# want to have an arbitrary order, since it might matter. being
# explicit is better.
(import ./nix/overlays/cargo-pgrx.nix)
(import ./nix/overlays/gdal-small.nix)
(import ./nix/overlays/psql_16-oriole.nix)

];
Expand Down Expand Up @@ -68,15 +67,10 @@
};
})
(import ./nix/overlays/cargo-pgrx-0-11-3.nix)
# (import ./nix/overlays/postgis.nix)
#(import ./nix/overlays/gdal-small.nix)

];
};
postgresql_15 = pkgs.postgresql.postgresql_15;
postgresql = pkgs.postgresql.postgresql_15;
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { inherit postgresql; };
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
Expand Down Expand Up @@ -284,14 +278,41 @@
# be used with 'nix build'. Don't use the names listed below; check the
# name in 'nix flake show' in order to make sure exactly what name you
# want.
basePackages = {
basePackages = let
# Function to get the PostgreSQL version from the attribute name
getVersion = name:
let
match = builtins.match "psql_([0-9]+)" name;
in
if match == null then null else builtins.head match;

# Define the available PostgreSQL versions
postgresVersions = {
psql_15 = makePostgres "15";
# Uncomment the line below to enable PostgreSQL 16
# psql_16 = makePostgres "16";
# psql_orioledb_16 = makeOrioleDbPostgres "16_23" postgresql_orioledb_16;
};

# Find the active PostgreSQL version
activeVersion = getVersion (builtins.head (builtins.attrNames postgresVersions));

# Function to create the pg_regress package
makePgRegress = version:
let
postgresqlPackage = pkgs."postgresql_${version}";
in
pkgs.callPackage ./nix/ext/pg_regress.nix {
postgresql = postgresqlPackage;
};

in
postgresVersions //{
supabase-groonga = supabase-groonga;
# PostgreSQL versions.
psql_15 = makePostgres "15";
#psql_16 = makePostgres "16";
#psql_orioledb_16 = makeOrioleDbPostgres "16_23" postgresql_orioledb_16;
sfcgal = sfcgal;
pg_regress = pg_regress;
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
postgresql_15 = pkgs.postgresql_15;

Expand Down Expand Up @@ -319,6 +340,7 @@
};
mecab_naist_jdic = mecab-naist-jdic;
supabase_groonga = supabase-groonga;
pg_regress = makePgRegress activeVersion;
# Start a version of the server.
start-server =
let
Expand Down Expand Up @@ -455,6 +477,7 @@
sqlTests = ./nix/tests/smoke;
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
pg_regress = basePackages.pg_regress;
in
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
{
Expand Down
69 changes: 69 additions & 0 deletions nix/ext/gdal.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{ lib
, stdenv
, fetchFromGitHub
, cmake
, pkg-config
, curl
, expat
, libgeotiff
, geos
, json_c
, libxml2
, postgresql
, proj
, sqlite
, libtiff
, zlib
}:

stdenv.mkDerivation rec {
pname = "gdal";
version = "3.8.5";

src = fetchFromGitHub {
owner = "OSGeo";
repo = "gdal";
rev = "v${version}";
hash = "sha256-Z+mYlyOX9vJ772qwZMQfCbD/V7RL6+9JLHTzoZ55ot0=";
};

nativeBuildInputs = [
cmake
pkg-config
];

buildInputs = [
curl
expat
libgeotiff
geos
json_c
libxml2
postgresql
proj
sqlite
libtiff
zlib
];

cmakeFlags = [
"-DGDAL_USE_INTERNAL_LIBS=OFF"
"-DGEOTIFF_INCLUDE_DIR=${lib.getDev libgeotiff}/include"
"-DGEOTIFF_LIBRARY_RELEASE=${lib.getLib libgeotiff}/lib/libgeotiff${stdenv.hostPlatform.extensions.sharedLibrary}"
"-DBUILD_PYTHON_BINDINGS=OFF"
] ++ lib.optionals (!stdenv.isDarwin) [
"-DCMAKE_SKIP_BUILD_RPATH=ON"
] ++ lib.optionals stdenv.isDarwin [
"-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON"
];

enableParallelBuilding = true;

meta = with lib; {
description = "Translator library for raster geospatial data formats (PostGIS-focused build)";
homepage = "https://www.gdal.org/";
license = licenses.mit;
maintainers = with maintainers; teams.geospatial.members ++ [ marcweber dotlambda ];
platforms = platforms.unix;
};
}
3 changes: 1 addition & 2 deletions nix/ext/postgis.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
, postgresql
, geos
, proj
, gdalMinimal
, json_c
, pkg-config
, file
Expand All @@ -17,8 +16,8 @@
}:

let
gdal = gdalMinimal;
sfcgal = callPackage ./sfcgal/sfcgal.nix { };
gdal = callPackage ./gdal.nix { inherit postgresql; };
in
stdenv.mkDerivation rec {
pname = "postgis";
Expand Down
14 changes: 0 additions & 14 deletions nix/overlays/gdal-small.nix

This file was deleted.

0 comments on commit 349cc83

Please sign in to comment.