Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

proj-data: init at 1.16.0 #280062

Closed
wants to merge 2 commits into from
Closed

proj-data: init at 1.16.0 #280062

wants to merge 2 commits into from

Conversation

imincik
Copy link
Contributor

@imincik imincik commented Jan 10, 2024

Description of changes

  • add initial version of proj-data package containing datum grid resource files for proj
    package
  • add optional support for installing proj-data grid resource files in proj data directory

AFAIK, installation of proj-data resource files in proj directory is the only user-friendly way of enabling them for all programs using proj. Another alternative methods are:

  • setting PROJ_DATA variable to ${proj}/share/proj:${proj-data} (see proj-data package tests)
  • adding them to user home directories

which can be very tricky for other applications using proj in containers or multi-user environments and can be error-prone.
For more information, see: https://proj.org/en/9.3/resource_files.html

Installation of proj-data files to proj is optional, because proj-data repository size is large (can reach 1GB of size soon) and it avoids downloading it when building proj package version where proj-data is not needed.

Example usage

  • Example of building proj package containing proj-data grids provided by nz_linz:
$ nix-build -E 'with import ./. {}; proj.override { proj-data = proj-data.override { gridPackages = ["nz_linz"]; };  withProjData = true; }'

ls ./result/share/proj
CH                               nz_linz_nzgd2000-20130801.json           nz_linz_nzgd2000-ka20161114-grid02.tif   nz_linz_nzgd2000-ndm-grid01.tif
deformation_model.schema.json    nz_linz_nzgd2000-20140201.json           nz_linz_nzgd2000-ka20161114-grid03.tif   nz_linz_nzgd2000-ndm-grid02.tif
GL27                             nz_linz_nzgd2000-20150101.json           nz_linz_nzgd2000-ka20161114-grid04.tif   nz_linz_nzgd2000-si20030821-grid01.tif
ITRF2000                         nz_linz_nzgd2000-20160701.json           nz_linz_nzgd2000-ka20161114-grid05.tif   nz_linz_nzgd2kgrid0005.tif
ITRF2008                         nz_linz_nzgd2000-20171201.json           nz_linz_nzgd2000-ka20161114-grid06.tif   nz_linz_nzgeoid2009.tif
ITRF2014                         nz_linz_nzgd2000-20180701.json           nz_linz_nzgd2000-ka20161114-grid07.tif   nz_linz_nzgeoid2016.tif
nad27                            nz_linz_nzgd2000-c120100904-grid01.tif   nz_linz_nzgd2000-ka20161114-grid08.tif   nz_linz_ontpht1964-nzvd2016.tif
nad83                            nz_linz_nzgd2000-c220110222-grid01.tif   nz_linz_nzgd2000-ka20161114-grid09.tif   nz_linz_README.txt
nad.lst                          nz_linz_nzgd2000-c320110613-grid01.tif   nz_linz_nzgd2000-ka20161114-grid10.tif   nz_linz_stisht1977-nzvd2016.tif
nz_linz_auckht1946-nzvd2016.tif  nz_linz_nzgd2000-c420111223-grid01.tif   nz_linz_nzgd2000-ka20161114-grid11.tif   nz_linz_taraht1970-nzvd2016.tif
nz_linz_blufht1955-nzvd2016.tif  nz_linz_nzgd2000-ch20160214-grid01.tif   nz_linz_nzgd2000-ka20161114-grid12.tif   nz_linz_wellht1953-nzvd2016.tif
nz_linz_dublht1960-nzvd2016.tif  nz_linz_nzgd2000-cs20130721-grid01.tif   nz_linz_nzgd2000-lg20130816-grid01.tif   other.extra
nz_linz_duneht1958-nzvd2016.tif  nz_linz_nzgd2000-cs20130721-grid02.tif   nz_linz_nzgd2000-lg20130816-grid02.tif   proj.db
nz_linz_gisbht1926-nzvd2016.tif  nz_linz_nzgd2000-ds20090715-grid011.tif  nz_linz_nzgd2000-mq20041223-grid011.tif  proj.ini
nz_linz_lyttht1937-nzvd2016.tif  nz_linz_nzgd2000-ds20090715-grid012.tif  nz_linz_nzgd2000-mq20041223-grid012.tif  projjson.schema.json
nz_linz_motuht1953-nzvd2016.tif  nz_linz_nzgd2000-ds20090715-grid013.tif  nz_linz_nzgd2000-mq20041223-grid013.tif  README-PROJ-DATA.md
nz_linz_napiht1962-nzvd2016.tif  nz_linz_nzgd2000-ds20090715-grid014.tif  nz_linz_nzgd2000-mq20041223-grid014.tif  triangulation.schema.json
nz_linz_nelsht1955-nzvd2016.tif  nz_linz_nzgd2000-gs20071016-grid01.tif   nz_linz_nzgd2000-mq20041223-grid015.tif  world
nz_linz_nzgd2000-20000101.json   nz_linz_nzgd2000-ka20161114-grid01.tif   nz_linz_nzgd2000-mq20041223-grid016.tif

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

@@ -58,6 +62,10 @@ stdenv.mkDerivation (finalAttrs: rec {

doCheck = true;

postInstall = lib.optionalString withProjData ''
cp -R ${proj-data}/* $out/share/proj/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cp -R ${proj-data}/* $out/share/proj/
cp --recursive "${proj-data}" "$out/share/proj"
  • GNU cp supports all of -R, -r, --recursive, and the last one is the most obvious.
  • If I understand correctly $out/share/proj doesn't exist at this point, so we can copy the entire directory across. * doesn't match dotfiles by default, so this also ensures that we copy everything.
  • Quote variables for general safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • GNU cp supports all of -R, -r, --recursive, and the last one is the most obvious.

Done. Thanks

  • If I understand correctly $out/share/proj doesn't exist at this point

Yes, it already exists and contains some files. No grid files should be hidden files, so I have no worries about not copying something what should be.

  • Quote variables for general safety.

I understand this point, but most of path variables in nixpkgs code (including the ones in this package) are not quoted. Nix store path can't contain any strange characters or spaces. I am leaving this unquoted for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Feel free to close any discussions where I've 馃憤'ed your last reply - I don't have access to close discussions.)

runHook preInstall
shopt -s extglob

mkdir -p $out
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
mkdir -p $out
mkdir -p "$out"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the comment about store path variables quoting above.

shopt -s extglob

mkdir -p $out
cp README.DATA $out/README-PROJ-DATA.md
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cp README.DATA $out/README-PROJ-DATA.md
cp README.DATA "$out"/README-PROJ-DATA.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the comment about store path variables quoting above.

cp README.DATA $out/README-PROJ-DATA.md

for grid in ${builtins.toString gridPackages}; do
if [ ! -d $grid ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this check redundant? The cp will fail if the directory doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this check doesn't exist, the error message is quite confusing

       > Running phase: installPhase
       > cp: missing destination file operand after '/nix/store/v3258iwkrrmh5iddli7sdzxgikiw3cyh-proj-data-1.16.0/'
       > Try 'cp --help' for more information.
```.

I prefer to leave it as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. In that case I'd recommend changing the check to if ! [[ -d "$grid" ]] - it won't produce a syntax error if anyone includes an empty grid package by accident.


for grid in ${builtins.toString gridPackages}; do
if [ ! -d $grid ]; then
echo "ERROR: Grid ($grid) does not exist."
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably go to stderr:

Suggested change
echo "ERROR: Grid ($grid) does not exist."
echo "ERROR: Grid ($grid) does not exist." >&2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good point. Done

exit 1
fi

cp $grid/!(*.sh|*.py) $out/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cp $grid/!(*.sh|*.py) $out/
cp "$grid"/!(*.sh|*.py) "$out"/

That said, would it be possible to create a positive rather than negative glob to include the relevant files? Something like *.json *.tif *.tiff *.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, but it is very hard to create future-proof list of allowed file types. I would prefer to leave it as is for now.

runCommand "${pname}-tests" { meta.timeout = 60; }
''
# add proj-data files to proj resources search path
export PROJ_DATA=${proj}/share/proj:${proj-data}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this possibly be set by the package itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what is the best approach. We can wrap all executables with PROJ_DATA path, but it wouldn't help with dozens of other apps using proj as library (like QGIS for example).

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure what is the best approach. We can wrap all executables with PROJ_DATA path, [鈥

Sounds good.

but it wouldn't help with dozens of other apps using proj as library (like QGIS for example).

Isn't that unrelated? We'd be making one thing work without breaking anything else, right?

let
# build custom package containing `nz_linz` grids
projDataWithGrid = finalAttrs.finalPackage.overrideAttrs (_: {
postInstall = "cp nz_linz/* $out/";
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this override gridPackages instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I would like to, but finalPackage doesn't support override (it supports only overrideAttrs). Any suggestions are welcome.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know Nix well enough to suggest anything. Feel free to ignore this, unless someone else has a suggestion.

inherit (proj-data) pname;
in
runCommand "${pname}-tests" { meta.timeout = 60; }
''
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is using pipelines, so set -o pipefail might help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, done.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/week-in-geospatial-team/37035/3

@imincik
Copy link
Contributor Author

imincik commented Jan 18, 2024

@dotlambda , are you OK with this PR ?

Copy link
Contributor

@l0b0 l0b0 left a comment

Choose a reason for hiding this comment

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

@imincik imincik marked this pull request as draft February 14, 2024 12:18
@imincik
Copy link
Contributor Author

imincik commented Feb 14, 2024

Consider using proj.[passthru.]withProjData instead of function parameter (see: #281739
for example).

@imincik
Copy link
Contributor Author

imincik commented Feb 22, 2024

I am replacing this PR with #290643 which is using better approach of adding grid packages to proj-data using withGridPackages passthru.

@imincik imincik closed this Feb 22, 2024
@emilylange emilylange deleted the proj-data-init branch May 14, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants