Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions pkgs/development/libraries/proj/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{ lib
, stdenv
, callPackage
, fetchFromGitHub
, fetchpatch

, cmake
, pkg-config
, buildPackages
, callPackage
, sqlite
, libtiff
, curl
Expand Down Expand Up @@ -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:
Copy link
Contributor

@l0b0 l0b0 Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't most packages implement optional add-ons as parameters to default.nix? That is, rather than installing pkgs.foo.overrides.withBar I'd install (pkgs.foo.override { withBar = true; }). See for example 1, 2.

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/
Copy link
Contributor

@l0b0 l0b0 Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than copying the data across, would it be possible to instead install proj-data and link to it from this package? That way there's only one way to install proj-data (and only ever one copy of each version), but proj can refer to that package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is not possible because $out/share/proj/ already contains data installed by proj. Otherwise I would do a symlink.

'';
});

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";
Expand Down
59 changes: 59 additions & 0 deletions pkgs/development/libraries/proj/proj-data.nix
Original file line number Diff line number Diff line change
@@ -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
'';
Copy link
Contributor

@l0b0 l0b0 Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind running this through shellcheck --shell=bash -? It does have a handful of issues. Ditto for the other shell scripts.


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;
};
})
26 changes: 24 additions & 2 deletions pkgs/development/libraries/proj/tests.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}