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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nik4: init at 1.8 #366194

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

nik4: init at 1.8 #366194

wants to merge 4 commits into from

Conversation

Luflosi
Copy link
Contributor

@Luflosi Luflosi commented Dec 18, 2024

Add nik4, a program that can render a map from OpenStreetMap data as an image.
openstreetmap-carto is an OpenStreetMap style. It defines how the map looks.
Also disable the broken python3Packages.python-mapnik test, since I need this dependency. It seems to work fine for this use-case.
I also wrote a NixOS test to show how everything fits together. If you run it (and wait many minutes), you get a nice map in the output.

I may or may not have gone a bit overboard with the openstreetmap-carto package, where I made it not depend on the internet, so it can run in the NixOS VM test. I also regenerate all automatically generated files that I could find and check that we get the same files. I also separated different parts into their own outputs. This way the closure size should be reduced if you don't need certain parts. For example the get-external-data.py script only needs to be run once to import the map into the database and after that, its huge closure (over two gigabytes) is no longer needed (unless you want to update the map).
I chose to use the latest git revision of openstreetmap-carto because it supports the flex layout, unlike the latest release.

@NixOS/geospatial please review.
I think this is a super cool demo.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 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.

@github-actions github-actions bot added 6.topic: python 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Dec 18, 2024
@Luflosi
Copy link
Contributor Author

Luflosi commented Dec 18, 2024

Also see https://nixcademy.com/posts/nixos-openstreetmap/ and https://github.com/tfc/nixos-openstreetmap, which does something similar.

@Luflosi
Copy link
Contributor Author

Luflosi commented Dec 18, 2024

I plan to create similar NixOS tests for calculating a route between two coordinates and also for full text search in the future.

@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by the maintainer of the package it changes labels Dec 19, 2024
@imincik
Copy link
Contributor

imincik commented Dec 19, 2024

Great work @Luflosi ! I'll review ASAP.

Copy link
Contributor

@imincik imincik left a comment

Choose a reason for hiding this comment

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

@Luflosi , thank you very much for interesting work and sorry for waiting so long for review.

I suggested some changes and might have a few comments later, but I'm pretty sure we get this merged soon !

BTW, you are very welcome to join Nix Geospatial Team.

pkgs/by-name/ni/nik4/package.nix Outdated Show resolved Hide resolved
pkgs/by-name/op/openstreetmap-carto/package.nix Outdated Show resolved Hide resolved
@@ -0,0 +1,210 @@
{
carto,
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I like when the list of function parameters is logically separated - lib and functions first and then packages (see gdal as an example).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok


# The original get-fonts.sh is currently broken, see https://github.com/gravitystorm/openstreetmap-carto/issues/5013
# This original script also does not aim to reproducible. It does not do any commit pinning or checksumming.
get_fonts = writeShellApplication {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of get_fonts script ? Also, I would try to avoid to run nix CLI (nix-store) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original get_fonts.sh script downloads fonts needed for properly rendering the map into a new directory in the current working directory. You can see an example of it being used (or at least prepared for use) here: https://github.com/tfc/nixos-openstreetmap/blob/0fd30b016eb838395d85948b9ecf00ff59b4581d/openstreetmap.nix#L67-L74. In that example renderd later makes use of these files.

I don't like the original script:

  • It's currently broken, see get-fonts fails, due to fonts.google.com not returning a zip. gravitystorm/openstreetmap-carto#5013
  • It spews warnings while running
  • It downloads old versions of the fonts from (among other places) a now archived repository
  • It doesn't do any checksumming or signature verification
    So I replaced it with my own version which just reuses fonts already packaged in Nixpkgs. I'm not using it in the NixOS test because I can pass the fonts directly to Nik4, which is more declarative than running an imperative step first.
    The reason why I chose to use the Nix CLI instead of copying the files was that I disliked the files being duplicated on disk. Nix just creates a symlink. But since you seem to really dislike using the Nix CLI, I replaced the call to nix with cp. I had to use --dereference since otherwise cp just copies the symlinks to the files in the Nix store themselves, which are not known to the garbage collector and will thus be deleted eventually.

"out"
"sql"
"lua"
"get_external_data"
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to rename this output.

Suggested change
"get_external_data"
"external_data"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The script is called get-external-data.py, so I named the output get_external_data. The output does not directly contain the external data but only a script that knows how to "get" it. Do you still think that I should rename it?

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 still in favor calling it external_data.

inherit hash;
};
};
simplified_water_polygons = mkArchive {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about moving all data downloading code to nixos/tests/nik4.nix test and generate external-data.yml file required for test script there ? It looks to me as a more appropriate place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal was to make this script as reproducible as possible, no matter if it's called in the NixOS test or on a users system. I'm in favor of keeping it this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this data ? Isn't it useful mostly for testing ? If that's true, I still lean more towards moving this code to the test.
Another issue of having this code in package is how to update this data over the time (and how often). We might end up with reproducible but very outdated data.

What do you think @autra ?

nixos/tests/nik4.nix Outdated Show resolved Hide resolved

# The original get-fonts.sh is currently broken, see https://github.com/gravitystorm/openstreetmap-carto/issues/5013
# This original script also does not aim to be reproducible. It does not do any commit pinning or checksumming.
get-fonts = writeShellApplication {
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't need to copy them. If I understand correctly, create a store path with all the needed font with symlinkJoin like you did, then patching font.mss here to make it use it would be better (at least more aligned with what I've seen in nixpkgs).

In fact, the very principle of get-fonts is not really what we do with nix/nixos (because, as you said elsewhere, it is neither reproducible nor predictable).

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 for that insight. I didn't know it was possible to patch the OSM style to depend directly on the fonts. I thought you needed to pass the fonts to the rendering software separately (such as Nik4 or renderd).

I removed the script.

@autra
Copy link
Contributor

autra commented Jan 16, 2025

I made 2 remarks, but things are already looking good! Thanks for starting this work :-)

Comment on lines +2 to +14
lib,
stdenvNoCC,
fetchFromGitHub,
fetchurl,

carto,
gdal,
hanazono,
nixosTests,
noto-fonts,
python3,
runCommand,
symlinkJoin,
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
lib,
stdenvNoCC,
fetchFromGitHub,
fetchurl,
carto,
gdal,
hanazono,
nixosTests,
noto-fonts,
python3,
runCommand,
symlinkJoin,
lib,
stdenvNoCC,
fetchFromGitHub,
fetchurl,
nixosTests,
runCommand,
symlinkJoin,
carto,
gdal,
hanazono,
noto-fonts,
python3,

"out"
"sql"
"lua"
"get_external_data"
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 still in favor calling it external_data.

inherit hash;
};
};
simplified_water_polygons = mkArchive {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this data ? Isn't it useful mostly for testing ? If that's true, I still lean more towards moving this code to the test.
Another issue of having this code in package is how to update this data over the time (and how often). We might end up with reproducible but very outdated data.

What do you think @autra ?

@autra
Copy link
Contributor

autra commented Jan 21, 2025

What do you think @autra ?

I think we should usually not package data, especially those data because they change quite often I'm sure. There are exceptions (proj reprojection grids I guess, even though it's probably debatable).

Considering that upstream's logic is to let the user downloading data via get_external_data.py and that you can specify the config, it seems the external_data.yml is just an example file. Because of that, I'm even more against packaging those data in the store: users may and will want other data.

In short everything that is not in upstream repository should not be packaged imo.

However, we can package the script and the default config file (and even patch the script so that it defaults to this config file in the store if necessary).

For the derivation output, I'd package all relevant scripts in openstreetmap-carto/scripts in the ${out}/bin/ output (correctly wrapped so that they work out of the box in nixos). I don't see the point of having separate outputs for get_external_data. I don't think we need to wrap all these scripts now though, just package those you need today @Luflosi.

For other files (styles? fonts if necessary?) I don't mind another output, but I wouldn't mind a folder in the main output, but I admit that the advantages of having different outputs or only one are not totally clear to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: python 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants