|
| 1 | +{ |
| 2 | + fetchFromGitHub, |
| 3 | + fetchurl, |
| 4 | + lib, |
| 5 | + stdenv, |
| 6 | + testers, |
| 7 | + |
| 8 | + jre, |
| 9 | + makeWrapper, |
| 10 | + maven, |
| 11 | + ... |
| 12 | +}: |
| 13 | +let |
| 14 | + version = builtins.fromTOML (builtins.readFile ./version.toml); |
| 15 | + |
| 16 | + src = fetchFromGitHub { |
| 17 | + owner = "graphhopper"; |
| 18 | + repo = "graphhopper"; |
| 19 | + tag = version.patch; |
| 20 | + hash = version.hash.src; |
| 21 | + }; |
| 22 | + |
| 23 | + # Patch graphhopper to remove the npm download |
| 24 | + patches = [ ./remove-npm-dependency.patch ]; |
| 25 | + |
| 26 | + # Graphhopper also relies on a maps bundle downloaded from npm |
| 27 | + # By default it installs nodejs and npm during the build, |
| 28 | + # But we patch that out so we much fetch it ourselves |
| 29 | + mapsBundle = fetchurl { |
| 30 | + name = "@graphhopper/graphhopper-maps-bundle-${version.mapsBundle}"; |
| 31 | + url = "https://registry.npmjs.org/@graphhopper/graphhopper-maps-bundle/-/graphhopper-maps-bundle-${version.mapsBundle}.tgz"; |
| 32 | + hash = version.hash.mapsBundle; |
| 33 | + }; |
| 34 | + |
| 35 | + # We cannot use `buildMavenPackage` as we need to load in the |
| 36 | + # mapsBundle before doing anything |
| 37 | + mvnDeps = stdenv.mkDerivation { |
| 38 | + name = "graphhopper-dependencies"; |
| 39 | + |
| 40 | + inherit src patches; |
| 41 | + |
| 42 | + buildInputs = [ maven ]; |
| 43 | + |
| 44 | + buildPhase = '' |
| 45 | + # Fetching deps with mvn dependency:go-offline does not quite catch everything, so we use this plugin instead |
| 46 | + mvn de.qaware.maven:go-offline-maven-plugin:resolve-dependencies \ |
| 47 | + -Dmaven.repo.local=$out/.m2 \ |
| 48 | + -Dmaven.wagon.rto=5000 |
| 49 | + ''; |
| 50 | + |
| 51 | + installPhase = '' |
| 52 | + # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside |
| 53 | + find $out -type f \( \ |
| 54 | + -name \*.lastUpdated \ |
| 55 | + -o -name resolver-status.properties \ |
| 56 | + -o -name _remote.repositories \) \ |
| 57 | + -delete |
| 58 | + ''; |
| 59 | + |
| 60 | + outputHashMode = "recursive"; |
| 61 | + outputHash = version.hash.mvnDeps; |
| 62 | + }; |
| 63 | +in |
| 64 | +stdenv.mkDerivation (finalAttrs: { |
| 65 | + pname = "graphhopper"; |
| 66 | + |
| 67 | + inherit src patches; |
| 68 | + |
| 69 | + version = version.patch; |
| 70 | + |
| 71 | + buildInputs = [ |
| 72 | + makeWrapper |
| 73 | + maven |
| 74 | + ]; |
| 75 | + |
| 76 | + configurePhase = '' |
| 77 | + runHook preConfigure |
| 78 | +
|
| 79 | + mkdir -p ./web-bundle/target/ |
| 80 | + ln -s ${mapsBundle} ./web-bundle/target/graphhopper-graphhopper-maps-bundle-${version.mapsBundle}.tgz |
| 81 | +
|
| 82 | + runHook postConfigure |
| 83 | + ''; |
| 84 | + |
| 85 | + # Build and skip tests because downloading of |
| 86 | + # test deps seems to not work with the go-offline plugin |
| 87 | + buildPhase = '' |
| 88 | + runHook preBuild |
| 89 | +
|
| 90 | + mvn package --offline \ |
| 91 | + -Dmaven.repo.local=${mvnDeps}/.m2 \ |
| 92 | + -DskipTests |
| 93 | +
|
| 94 | + runHook postBuild |
| 95 | + ''; |
| 96 | + |
| 97 | + installPhase = '' |
| 98 | + runHook preInstall |
| 99 | +
|
| 100 | + mkdir -p $out/bin |
| 101 | +
|
| 102 | + ln -s ${mvnDeps}/.m2 $out/lib |
| 103 | +
|
| 104 | + # Grapphopper versions are seemingly compiled under the major release name, |
| 105 | + # not the patch name, which is the version we want for our package |
| 106 | + cp ./web/target/graphhopper-web-${version.major}-SNAPSHOT.jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar |
| 107 | +
|
| 108 | + makeWrapper ${jre}/bin/java $out/bin/graphhopper \ |
| 109 | + --add-flags "-jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar" \ |
| 110 | + --chdir $out |
| 111 | +
|
| 112 | + runHook postInstall |
| 113 | + ''; |
| 114 | + |
| 115 | + fixupPhase = '' |
| 116 | + runHook preFixup |
| 117 | +
|
| 118 | + # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside |
| 119 | + find $out -type f \( \ |
| 120 | + -name \*.lastUpdated \ |
| 121 | + -o -name resolver-status.properties \ |
| 122 | + -o -name _remote.repositories \) \ |
| 123 | + -delete |
| 124 | +
|
| 125 | + runHook postFixup |
| 126 | + ''; |
| 127 | + |
| 128 | + meta = { |
| 129 | + description = "Fast and memory-efficient routing engine for OpenStreetMap"; |
| 130 | + homepage = "https://www.graphhopper.com/"; |
| 131 | + changelog = "https://github.com/graphhopper/graphhopper/releases/tag/${version.patch}"; |
| 132 | + license = lib.licenses.asl20; |
| 133 | + maintainers = with lib.maintainers; [ baileylu ]; |
| 134 | + teams = [ lib.teams.geospatial ]; |
| 135 | + platforms = lib.platforms.all; |
| 136 | + mainProgram = "graphhopper"; |
| 137 | + sourceProvenance = with lib.sourceTypes; [ |
| 138 | + fromSource |
| 139 | + binaryBytecode |
| 140 | + ]; |
| 141 | + }; |
| 142 | + |
| 143 | + passthru = { |
| 144 | + updateScript = ./update.nu; |
| 145 | + tests.version = testers.testVersion { |
| 146 | + package = finalAttrs.finalPackage; |
| 147 | + # `graphhopper --version` does not work as the source does not specify `Implementation-Version` |
| 148 | + command = "graphhopper --help"; |
| 149 | + version = "graphhopper-web-${version.major}-SNAPSHOT.jar"; |
| 150 | + }; |
| 151 | + }; |
| 152 | +}) |
0 commit comments