diff --git a/flake.nix b/flake.nix index 1f9d5f64d..03106015b 100644 --- a/flake.nix +++ b/flake.nix @@ -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) ]; @@ -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. @@ -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; @@ -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 @@ -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" { diff --git a/nix/ext/gdal.nix b/nix/ext/gdal.nix new file mode 100644 index 000000000..83924d9ff --- /dev/null +++ b/nix/ext/gdal.nix @@ -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; + }; +} diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index fcf1a8a56..bb9a6162a 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -5,7 +5,6 @@ , postgresql , geos , proj -, gdalMinimal , json_c , pkg-config , file @@ -17,8 +16,8 @@ }: let - gdal = gdalMinimal; sfcgal = callPackage ./sfcgal/sfcgal.nix { }; + gdal = callPackage ./gdal.nix { inherit postgresql; }; in stdenv.mkDerivation rec { pname = "postgis"; diff --git a/nix/overlays/gdal-small.nix b/nix/overlays/gdal-small.nix deleted file mode 100644 index 18be8a526..000000000 --- a/nix/overlays/gdal-small.nix +++ /dev/null @@ -1,14 +0,0 @@ -final: prev: { - # override the version of gdal used with postgis with the small version. - # significantly reduces overall closure size - gdal = prev.gdalMinimal.override { - /* other features can be enabled, reference: - https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gdal/default.nix - */ - - # useHDF = true; - # useArrow = true; - # useLibHEIF = true; - # ... - }; -}