Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 fetchFromGitHub, 3 fetchurl, 4 lib, 5 stdenv, 6 testers, 7 8 jre, 9 makeWrapper, 10 maven, 11 ... 12}: 13let 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 }; 63in 64stdenv.mkDerivation (finalAttrs: { 65 pname = "graphhopper"; 66 67 inherit src patches; 68 69 version = version.patch; 70 71 nativeBuildInputs = [ 72 makeWrapper 73 maven 74 ]; 75 76 strictDeps = true; 77 78 configurePhase = '' 79 runHook preConfigure 80 81 mkdir -p ./web-bundle/target/ 82 ln -s ${mapsBundle} ./web-bundle/target/graphhopper-graphhopper-maps-bundle-${version.mapsBundle}.tgz 83 84 runHook postConfigure 85 ''; 86 87 # Build and skip tests because downloading of 88 # test deps seems to not work with the go-offline plugin 89 buildPhase = '' 90 runHook preBuild 91 92 mvn package --offline \ 93 -Dmaven.repo.local=${mvnDeps}/.m2 \ 94 -DskipTests 95 96 runHook postBuild 97 ''; 98 99 installPhase = '' 100 runHook preInstall 101 102 mkdir -p $out/bin 103 104 ln -s ${mvnDeps}/.m2 $out/lib 105 106 # Grapphopper versions are seemingly compiled under the major release name, 107 # not the patch name, which is the version we want for our package 108 cp ./web/target/graphhopper-web-${version.major}-SNAPSHOT.jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar 109 110 makeWrapper ${jre}/bin/java $out/bin/graphhopper \ 111 --add-flags "-jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar" \ 112 --chdir $out 113 114 runHook postInstall 115 ''; 116 117 fixupPhase = '' 118 runHook preFixup 119 120 # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside 121 find $out -type f \( \ 122 -name \*.lastUpdated \ 123 -o -name resolver-status.properties \ 124 -o -name _remote.repositories \) \ 125 -delete 126 127 runHook postFixup 128 ''; 129 130 meta = { 131 description = "Fast and memory-efficient routing engine for OpenStreetMap"; 132 homepage = "https://www.graphhopper.com/"; 133 changelog = "https://github.com/graphhopper/graphhopper/releases/tag/${version.patch}"; 134 license = lib.licenses.asl20; 135 maintainers = with lib.maintainers; [ baileylu ]; 136 teams = [ lib.teams.geospatial ]; 137 platforms = lib.platforms.all; 138 mainProgram = "graphhopper"; 139 sourceProvenance = with lib.sourceTypes; [ 140 fromSource 141 binaryBytecode 142 ]; 143 }; 144 145 passthru = { 146 updateScript = ./update.nu; 147 tests.version = testers.testVersion { 148 package = finalAttrs.finalPackage; 149 # `graphhopper --version` does not work as the source does not specify `Implementation-Version` 150 command = "graphhopper --help"; 151 version = "graphhopper-web-${version.major}-SNAPSHOT.jar"; 152 }; 153 }; 154})