diff --git a/pkgs/development/libraries/proj/default.nix b/pkgs/development/libraries/proj/default.nix index 326f219cddda2..7c4bf4a48949c 100644 --- a/pkgs/development/libraries/proj/default.nix +++ b/pkgs/development/libraries/proj/default.nix @@ -1,11 +1,11 @@ { lib , stdenv +, callPackage , fetchFromGitHub -, fetchpatch + , cmake , pkg-config , buildPackages -, callPackage , sqlite , libtiff , curl @@ -62,10 +62,27 @@ stdenv.mkDerivation (finalAttrs: { doCheck = true; - passthru.tests = { - python = python3.pkgs.pyproj; - proj = callPackage ./tests.nix { proj = finalAttrs.finalPackage; }; - }; + passthru = + let + proj = finalAttrs.finalPackage; + in + { + withProjData = gridPackages: + let + proj-data = callPackage ./proj-data.nix { gridPackages = gridPackages; }; + in + proj.overrideAttrs (final: prev: { + pname = prev.pname + "-with-grid-packages"; + postInstall = '' + cp --recursive ${proj-data}/* $out/share/proj/ + ''; + }); + + tests = { + python = python3.pkgs.pyproj; + proj = callPackage ./tests.nix { proj = finalAttrs.finalPackage; }; + }; + }; meta = with lib; { changelog = "https://github.com/OSGeo/PROJ/blob/${finalAttrs.src.rev}/NEWS"; diff --git a/pkgs/development/libraries/proj/proj-data.nix b/pkgs/development/libraries/proj/proj-data.nix new file mode 100644 index 0000000000000..ac43fbd4cf083 --- /dev/null +++ b/pkgs/development/libraries/proj/proj-data.nix @@ -0,0 +1,59 @@ +{ lib +, stdenv +, fetchFromGitHub + + # By default, no grids packages are installed due to a large size of this + # repository. Current size of all proj-data grids is almost 1GB and will only + # grow over the time. +, gridPackages ? [ ] +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "proj-data"; + version = "1.16.0"; + + src = fetchFromGitHub { + owner = "OSGeo"; + repo = "PROJ-data"; + rev = finalAttrs.version; + hash = "sha256-/EgDeWy2+KdcI4DLsRfWi5OWcGwO3AieEJQ5Zh+wdYE="; + }; + + installPhase = '' + runHook preInstall + shopt -s extglob + + mkdir -p $out + cp README.DATA $out/README-PROJ-DATA.md + + for grid in ${builtins.toString gridPackages}; do + if [ ! -d $grid ]; then + echo "ERROR: proj-data grid $grid does not exist." >&2 + exit 1 + fi + + cp $grid/!(*.sh|*.py) $out/ + done + + shopt -u extglob + runHook postInstall + ''; + + meta = with lib; { + description = "Repository for proj datum grids (for use by PROJ 7 or later)"; + homepage = "https://proj4.org"; + # Licensing note: + # All grids in the package are released under permissive licenses. New grids + # are accepted into the package as long as they are released under a license that + # is compatible with the Open Source Definition and the source of the grid is + # clearly stated and verifiable. Suitable licenses include: + # Public domain + # X/MIT + # BSD 2/3/4 clause + # CC0 + # CC-BY (v3.0 or later) + # CC-BY-SA (v3.0 or later) + license = licenses.mit; + maintainers = teams.geospatial.members; + }; +}) diff --git a/pkgs/development/libraries/proj/tests.nix b/pkgs/development/libraries/proj/tests.nix index 38126f06dd4d6..07c6f1364de1b 100644 --- a/pkgs/development/libraries/proj/tests.nix +++ b/pkgs/development/libraries/proj/tests.nix @@ -1,11 +1,33 @@ -{ runCommand, proj }: +{ pkgs, runCommand, proj }: let inherit (proj) pname; + projWithData = pkgs.proj.withProjData [ "nz_linz" ]; + in -runCommand "${pname}-tests" { meta.timeout = 60; } +{ + proj-no-data = runCommand "${pname}-no-data-tests" { } '' ${proj}/bin/projinfo EPSG:4326 \ | grep '+proj=longlat +datum=WGS84 +no_defs +type=crs' touch $out + ''; + + proj-with-data = runCommand "${pname}-with-data-tests" { } '' + set -o pipefail + + # conversion from NZGD1949 to NZGD2000 using proj strings + echo '173 -41 0' \ + | ${projWithData}/bin/cs2cs --only-best -f %.8f \ + +proj=longlat +ellps=intl +datum=nzgd49 +nadgrids=nz_linz_nzgd2kgrid0005.tif \ + +to +proj=longlat +ellps=GRS80 +towgs84=0,0,0 \ + | grep -E '[0-9\.\-]+*' + + # conversion from NZGD1949 to NZGD2000 using EPSG codes + echo '-41 173 0' | ${projWithData}/bin/cs2cs --only-best -f %.8f EPSG:4272 EPSG:4167 \ + | grep -E '[0-9\.\-]+*' + + touch $out + ''; +}