Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 cmake,
3 fetchFromGitHub,
4 h3_4,
5 lib,
6 postgresql,
7 postgresqlBuildExtension,
8 postgresqlTestExtension,
9 stdenv,
10}:
11
12postgresqlBuildExtension (finalAttrs: {
13 pname = "h3-pg";
14 version = "4.2.3";
15
16 src = fetchFromGitHub {
17 owner = "zachasme";
18 repo = "h3-pg";
19 tag = "v${finalAttrs.version}";
20 hash = "sha256-kTh0Y0C2pNB5Ul1rp77ets/5VeU1zw1WasGHkOaDMh8=";
21 };
22
23 postPatch = ''
24 substituteInPlace CMakeLists.txt \
25 --replace-fail "add_subdirectory(cmake/h3)" "include_directories(${lib.getDev h3_4}/include/h3)"
26 ''
27 + lib.optionalString stdenv.hostPlatform.isDarwin ''
28 substituteInPlace cmake/AddPostgreSQLExtension.cmake \
29 --replace-fail "INTERPROCEDURAL_OPTIMIZATION TRUE" ""
30 '';
31
32 nativeBuildInputs = [
33 cmake
34 ];
35
36 buildInputs = [
37 h3_4
38 ];
39
40 passthru.tests.extension = postgresqlTestExtension {
41 inherit (finalAttrs) finalPackage;
42 withPackages = [ "postgis" ];
43 sql = ''
44 CREATE EXTENSION h3;
45 CREATE EXTENSION h3_postgis CASCADE;
46
47 SELECT h3_lat_lng_to_cell(POINT('37.3615593,-122.0553238'), 5);
48 SELECT ST_NPoints(h3_cell_to_boundary_geometry('8a63a9a99047fff'));
49 '';
50 };
51
52 meta = {
53 description = "PostgreSQL bindings for H3, a hierarchical hexagonal geospatial indexing system";
54 homepage = "https://github.com/zachasme/h3-pg";
55 license = lib.licenses.asl20;
56 maintainers = [ ];
57 inherit (postgresql.meta) platforms;
58 };
59})