Skip to content

Commit 349cc83

Browse files
authored
feat: package gdal + fix basePackages to switch pg version correctly (#1231)
Co-authored-by: Sam Rose <[email protected]>
1 parent 092d970 commit 349cc83

File tree

4 files changed

+102
-25
lines changed

4 files changed

+102
-25
lines changed

flake.nix

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
# want to have an arbitrary order, since it might matter. being
3939
# explicit is better.
4040
(import ./nix/overlays/cargo-pgrx.nix)
41-
(import ./nix/overlays/gdal-small.nix)
4241
(import ./nix/overlays/psql_16-oriole.nix)
4342

4443
];
@@ -68,15 +67,10 @@
6867
};
6968
})
7069
(import ./nix/overlays/cargo-pgrx-0-11-3.nix)
71-
# (import ./nix/overlays/postgis.nix)
72-
#(import ./nix/overlays/gdal-small.nix)
73-
7470
];
7571
};
7672
postgresql_15 = pkgs.postgresql.postgresql_15;
77-
postgresql = pkgs.postgresql.postgresql_15;
7873
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
79-
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { inherit postgresql; };
8074
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
8175
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
8276
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
@@ -284,14 +278,41 @@
284278
# be used with 'nix build'. Don't use the names listed below; check the
285279
# name in 'nix flake show' in order to make sure exactly what name you
286280
# want.
287-
basePackages = {
281+
basePackages = let
282+
# Function to get the PostgreSQL version from the attribute name
283+
getVersion = name:
284+
let
285+
match = builtins.match "psql_([0-9]+)" name;
286+
in
287+
if match == null then null else builtins.head match;
288+
289+
# Define the available PostgreSQL versions
290+
postgresVersions = {
291+
psql_15 = makePostgres "15";
292+
# Uncomment the line below to enable PostgreSQL 16
293+
# psql_16 = makePostgres "16";
294+
# psql_orioledb_16 = makeOrioleDbPostgres "16_23" postgresql_orioledb_16;
295+
};
296+
297+
# Find the active PostgreSQL version
298+
activeVersion = getVersion (builtins.head (builtins.attrNames postgresVersions));
299+
300+
# Function to create the pg_regress package
301+
makePgRegress = version:
302+
let
303+
postgresqlPackage = pkgs."postgresql_${version}";
304+
in
305+
pkgs.callPackage ./nix/ext/pg_regress.nix {
306+
postgresql = postgresqlPackage;
307+
};
308+
309+
in
310+
postgresVersions //{
288311
supabase-groonga = supabase-groonga;
289312
# PostgreSQL versions.
290313
psql_15 = makePostgres "15";
291-
#psql_16 = makePostgres "16";
292314
#psql_orioledb_16 = makeOrioleDbPostgres "16_23" postgresql_orioledb_16;
293315
sfcgal = sfcgal;
294-
pg_regress = pg_regress;
295316
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
296317
postgresql_15 = pkgs.postgresql_15;
297318

@@ -319,6 +340,7 @@
319340
};
320341
mecab_naist_jdic = mecab-naist-jdic;
321342
supabase_groonga = supabase-groonga;
343+
pg_regress = makePgRegress activeVersion;
322344
# Start a version of the server.
323345
start-server =
324346
let
@@ -455,6 +477,7 @@
455477
sqlTests = ./nix/tests/smoke;
456478
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
457479
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
480+
pg_regress = basePackages.pg_regress;
458481
in
459482
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
460483
{

nix/ext/gdal.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{ lib
2+
, stdenv
3+
, fetchFromGitHub
4+
, cmake
5+
, pkg-config
6+
, curl
7+
, expat
8+
, libgeotiff
9+
, geos
10+
, json_c
11+
, libxml2
12+
, postgresql
13+
, proj
14+
, sqlite
15+
, libtiff
16+
, zlib
17+
}:
18+
19+
stdenv.mkDerivation rec {
20+
pname = "gdal";
21+
version = "3.8.5";
22+
23+
src = fetchFromGitHub {
24+
owner = "OSGeo";
25+
repo = "gdal";
26+
rev = "v${version}";
27+
hash = "sha256-Z+mYlyOX9vJ772qwZMQfCbD/V7RL6+9JLHTzoZ55ot0=";
28+
};
29+
30+
nativeBuildInputs = [
31+
cmake
32+
pkg-config
33+
];
34+
35+
buildInputs = [
36+
curl
37+
expat
38+
libgeotiff
39+
geos
40+
json_c
41+
libxml2
42+
postgresql
43+
proj
44+
sqlite
45+
libtiff
46+
zlib
47+
];
48+
49+
cmakeFlags = [
50+
"-DGDAL_USE_INTERNAL_LIBS=OFF"
51+
"-DGEOTIFF_INCLUDE_DIR=${lib.getDev libgeotiff}/include"
52+
"-DGEOTIFF_LIBRARY_RELEASE=${lib.getLib libgeotiff}/lib/libgeotiff${stdenv.hostPlatform.extensions.sharedLibrary}"
53+
"-DBUILD_PYTHON_BINDINGS=OFF"
54+
] ++ lib.optionals (!stdenv.isDarwin) [
55+
"-DCMAKE_SKIP_BUILD_RPATH=ON"
56+
] ++ lib.optionals stdenv.isDarwin [
57+
"-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON"
58+
];
59+
60+
enableParallelBuilding = true;
61+
62+
meta = with lib; {
63+
description = "Translator library for raster geospatial data formats (PostGIS-focused build)";
64+
homepage = "https://www.gdal.org/";
65+
license = licenses.mit;
66+
maintainers = with maintainers; teams.geospatial.members ++ [ marcweber dotlambda ];
67+
platforms = platforms.unix;
68+
};
69+
}

nix/ext/postgis.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
, postgresql
66
, geos
77
, proj
8-
, gdalMinimal
98
, json_c
109
, pkg-config
1110
, file
@@ -17,8 +16,8 @@
1716
}:
1817

1918
let
20-
gdal = gdalMinimal;
2119
sfcgal = callPackage ./sfcgal/sfcgal.nix { };
20+
gdal = callPackage ./gdal.nix { inherit postgresql; };
2221
in
2322
stdenv.mkDerivation rec {
2423
pname = "postgis";

nix/overlays/gdal-small.nix

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)