diff --git a/pkgs/by-name/pr/proj-data/package.nix b/pkgs/by-name/pr/proj-data/package.nix new file mode 100644 index 0000000000000..fc12f61946b79 --- /dev/null +++ b/pkgs/by-name/pr/proj-data/package.nix @@ -0,0 +1,73 @@ +{ lib +, stdenv +, callPackage +, fetchFromGitHub + + # proj-data grid directories to install (ex.: "nz_linz"). + # By default, no grids are installed due to the large size (size of all proj- + # data grids is nearly 1GB and will 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: Grid ($grid) does not exist." >&2 + exit 1 + fi + + cp $grid/!(*.sh|*.py) $out/ + done + + shopt -u extglob + runHook postInstall + ''; + + passthru.tests = + let + # build custom package containing `nz_linz` grids + projDataWithGrid = finalAttrs.finalPackage.overrideAttrs (_: { + postInstall = "cp nz_linz/* $out/"; + }); + in + { + proj-data = callPackage ./tests.nix { + proj-data = projDataWithGrid; + }; + }; + + 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/by-name/pr/proj-data/tests.nix b/pkgs/by-name/pr/proj-data/tests.nix new file mode 100644 index 0000000000000..09ac84a72ec27 --- /dev/null +++ b/pkgs/by-name/pr/proj-data/tests.nix @@ -0,0 +1,25 @@ +{ runCommand, proj, proj-data }: + +let + inherit (proj-data) pname; +in +runCommand "${pname}-tests" { meta.timeout = 60; } + '' + set -o pipefail + + # add proj-data files to proj resources search path + export PROJ_DATA=${proj}/share/proj:${proj-data} + + # conversion from NZGD1949 to NZGD2000 using proj strings + echo '173 -41 0' \ + | ${proj}/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' | ${proj}/bin/cs2cs --only-best -f %.8f EPSG:4272 EPSG:4167 \ + | grep -E '[0-9\.\-]+*' + + touch $out + '' diff --git a/pkgs/development/libraries/proj/default.nix b/pkgs/development/libraries/proj/default.nix index fedb1b003d96e..759b39a026b92 100644 --- a/pkgs/development/libraries/proj/default.nix +++ b/pkgs/development/libraries/proj/default.nix @@ -1,11 +1,14 @@ { lib , stdenv +, callPackage , fetchFromGitHub -, fetchpatch + +# install grid resource files from proj-data package +, withProjData ? false + , cmake , pkg-config , buildPackages -, callPackage , sqlite , libtiff , curl @@ -13,6 +16,7 @@ , nlohmann_json , python3 , cacert +, proj-data }: stdenv.mkDerivation (finalAttrs: rec { @@ -58,6 +62,10 @@ stdenv.mkDerivation (finalAttrs: rec { doCheck = true; + postInstall = lib.optionalString withProjData '' + cp --recursive ${proj-data}/* $out/share/proj/ + ''; + passthru.tests = { python = python3.pkgs.pyproj; proj = callPackage ./tests.nix { proj = finalAttrs.finalPackage; };