Skip to content

Commit

Permalink
nixos/tests/nik4: init
Browse files Browse the repository at this point in the history
  • Loading branch information
Luflosi committed Jan 19, 2025
1 parent 9375279 commit 879c55e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ in {
nix-channel = pkgs.callPackage ../modules/config/nix-channel/test.nix { };
nebula = handleTest ./nebula.nix {};
netbird = handleTest ./netbird.nix {};
nik4 = runTest ./nik4.nix;
nimdow = handleTest ./nimdow.nix {};
neo4j = handleTest ./neo4j.nix {};
netdata = handleTest ./netdata.nix {};
Expand Down
69 changes: 69 additions & 0 deletions nixos/tests/nik4.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This test downloads some example OpenStreetMap data, imports it into a database and then renders a portion of it. The resulting PNG image will be in the output.
# Importing the data takes some time, at least a couple minutes.

{ lib, pkgs, ... }:
let
# Fetch a tiny example region
andorra = pkgs.fetchurl {
# The OpenStreetMap data from the first of January seems to be kept for at least 10 years
url = "https://download.geofabrik.de/europe/andorra-240101.osm.pbf";
hash = "sha256-9RylVK1C28e9qnc8Lu1VGcxS3lNlmjPTWcWvJJlmAf4=";
};
in
{
name = "nik4";
meta.maintainers = lib.teams.geospatial.members ++ (with lib.maintainers; [ Luflosi ]);

nodes.machine = {
virtualisation = {
cores = 2;
diskSize = 8 * 1024;
memorySize = 2 * 1024;
};

services.postgresql = {
enable = true;
extensions = ps: with ps; [ postgis ];
ensureUsers = lib.singleton {
name = "osmuser";
ensureClauses.createdb = true;
};
};

users.users.osmuser = {
isSystemUser = true;
group = "osmuser";
};
users.groups.osmuser = { };

environment.systemPackages = with pkgs; [
osm2pgsql
nik4
];
};

testScript = ''
machine.wait_for_unit("multi-user.target")
with subtest("Create database"):
machine.succeed("sudo -u postgres createdb --encoding=UTF8 --owner=osmuser gis")
machine.succeed("sudo -u postgres psql gis --command='CREATE EXTENSION postgis;'")
machine.succeed("sudo -u postgres psql gis --command='CREATE EXTENSION hstore;'")
with subtest("Insert data into database"):
machine.succeed("mkdir /osm >&2")
machine.succeed("chown osmuser /osm >&2")
machine.succeed("sudo -u osmuser '${pkgs.openstreetmap-carto.get_external_data}/bin/get-external-data.py' --config '${pkgs.openstreetmap-carto.get_external_data}/external-data.yml' --data '/osm/get-external-data/'")
machine.succeed("sudo -u osmuser osm2pgsql --output=flex --style='${pkgs.openstreetmap-carto}/openstreetmap-carto-flex.lua' --database=gis --create '${andorra}'")
machine.succeed("sudo -u osmuser psql -d gis -f '${pkgs.openstreetmap-carto}/indexes.sql'")
machine.succeed("sudo -u osmuser psql -d gis -f '${pkgs.openstreetmap-carto}/functions.sql'")
with subtest("Execute nik4.py"):
machine.succeed("sudo -u osmuser nik4.py --fonts '${pkgs.openstreetmap-carto.passthru.fonts}' --url 'https://www.openstreetmap.org/#map=17/42.506650/1.525828' --ppi 300 -a 4 '${pkgs.openstreetmap-carto}/mapnik.xml' /tmp/map.png >&2")
machine.copy_from_vm("/tmp/map.png")
import os
image_size = os.stat(machine.out_dir / "map.png").st_size
assert image_size >= 2 * 1024 * 1024, f"The rendered map image was too small ({image_size} bytes). This indicates, that the map was not rendered correctly."
'';
}
5 changes: 5 additions & 0 deletions pkgs/by-name/ni/nik4/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
lib,
fetchFromGitHub,

nixosTests,
python3Packages,
}:

Expand All @@ -26,6 +27,10 @@ python3Packages.buildPythonPackage rec {

strictDeps = true;

passthru.tests = {
inherit (nixosTests) nik4;
};

meta = {
changelog = "https://github.com/Zverik/Nik4/releases/tag/v${version}";
description = "Mapnik to image export";
Expand Down
2 changes: 2 additions & 0 deletions pkgs/by-name/op/openstreetmap-carto/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
coreutils,
gdal,
hanazono,
nixosTests,
noto-fonts,
python3,
runCommand,
Expand Down Expand Up @@ -173,6 +174,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
};

tests = {
inherit (nixosTests) nik4;
inherit (finalAttrs.finalPackage.passthru) fonts get-fonts;

# Check that we generated the exact same files as the pre-generated ones
Expand Down

0 comments on commit 879c55e

Please sign in to comment.