diff --git a/flake.lock b/flake.lock index f133326..12941fe 100644 --- a/flake.lock +++ b/flake.lock @@ -622,6 +622,23 @@ "type": "github" } }, + "osrm-backend": { + "flake": false, + "locked": { + "lastModified": 1731259907, + "narHash": "sha256-WD7QvwGaJZRaFCdlrPxMWU6zhkZJIQ7veWdkJrzm65E=", + "owner": "nammayatri", + "repo": "osrm-backend", + "rev": "07851a158536a477082aa546c69d7e1928b7a284", + "type": "github" + }, + "original": { + "owner": "nammayatri", + "ref": "Backend/feat/adding-one-to-one-distance-calculation", + "repo": "osrm-backend", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": [ @@ -724,6 +741,7 @@ "common", "nixpkgs" ], + "osrm-backend": "osrm-backend", "systems": [ "common", "systems" diff --git a/flake.nix b/flake.nix index c0d91e9..95a93ef 100644 --- a/flake.nix +++ b/flake.nix @@ -8,17 +8,22 @@ # data files india-latest.url = "https://download.geofabrik.de/asia/india-latest.osm.pbf"; india-latest.flake = false; + + osrm-backend = { + url = "github:nammayatri/osrm-backend/Backend/feat/adding-one-to-one-distance-calculation"; + flake = false; + }; }; outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { systems = import inputs.systems; imports = [ - ./osrm.nix + (import ./osrm.nix { osrmBackend = inputs.osrm-backend; inherit inputs; }) ./docker.nix ]; perSystem = { self', pkgs, lib, ... }: { formatter = pkgs.nixpkgs-fmt; }; }; -} +} \ No newline at end of file diff --git a/osrm.nix b/osrm.nix index c302c65..1f6914d 100644 --- a/osrm.nix +++ b/osrm.nix @@ -1,4 +1,4 @@ -{ inputs, ... }: +{ osrmBackend, inputs, ... }: let openStreetDataFileName = "india-latest"; @@ -11,31 +11,68 @@ in packages = rec { # Patch osrm-backend to use our own car.lua file - osrm-backend = pkgs.osrm-backend.overrideAttrs (oa: { - # TODO: Use `patches` to directly patch the car.lua file. - # Or, use a fork of osrm-backend, and point to it. - src = pkgs.runCommandNoCC "osrm-backend-patched-src" { } '' - cp -r ${oa.src} $out - chmod -R u+w $out + patched-osrm-backend = pkgs.stdenv.mkDerivation { + name = "patched-osrm-backend"; + src = osrmBackend; + buildInputs = [ + pkgs.cmake + pkgs.boost + pkgs.tbb_2021_8 # Use TBB 2021.8 explicitly + pkgs.expat + pkgs.bzip2 + pkgs.libzip + pkgs.pkg-config + pkgs.lua5_2 # Updated to Lua 5.3 + ]; + + phases = [ "unpackPhase" "buildPhase" "installPhase" ]; + buildPhase = '' + mkdir build + cd build + cmake .. \ + -DENABLE_MASON=ON \ + -DTBB_ROOT=${pkgs.tbb_2021_8} \ + -DCMAKE_PREFIX_PATH="${pkgs.boost};${pkgs.tbb_2021_8};${pkgs.expat};${pkgs.bzip2};${pkgs.lua5_3}" \ + -DCMAKE_CXX_STANDARD=20 \ + -DCMAKE_CXX_FLAGS="-std=c++20 -stdlib=libc++" \ + -DCMAKE_INSTALL_PREFIX=$out + make + ''; + installPhase = '' + mkdir -p $out/bin $out/profiles + cp build/osrm-* $out/bin/ cp ${carLuaPath} $out/profiles/car.lua ''; - }); - - osrm-data = - pkgs.runCommandNoCC "osrm-data" - { buildInputs = [ self'.packages.osrm-backend ]; } - '' - mkdir $out && cd $out - ln -s ${inputs.india-latest} ${openStreetDataFileName}.osm.pbf - ln -s ${speedDataPath} ${indiaSpeedDataFileName}.csv - osrm-extract -p ${self'.packages.osrm-backend}/share/osrm/profiles/car.lua ${openStreetDataFileName}.osm.pbf - osrm-partition ${openStreetDataFileName}.osrm - osrm-customize --segment-speed-file ${indiaSpeedDataFileName}.csv ${openStreetDataFileName}.osrm - ''; + }; + + osrm-data = pkgs.runCommandNoCC "osrm-data" + { buildInputs = [ patched-osrm-backend ]; } + '' + mkdir -p $out && cd $out + + # Link input files + ln -s ${inputs.india-latest} ${openStreetDataFileName}.osm.pbf + ln -s ${speedDataPath} ${indiaSpeedDataFileName}.csv + + # Run OSRM tools + ${patched-osrm-backend}/bin/osrm-extract \ + -p ${patched-osrm-backend}/profiles/car.lua \ + ${openStreetDataFileName}.osm.pbf + + ${patched-osrm-backend}/bin/osrm-partition \ + ${openStreetDataFileName}.osrm + + ${patched-osrm-backend}/bin/osrm-customize \ + --segment-speed-file ${indiaSpeedDataFileName}.csv \ + ${openStreetDataFileName}.osrm + + # Move processed data to output directory + cp ${openStreetDataFileName}.* $out/ + ''; osrm-server = pkgs.writeShellApplication { name = "osrm-server"; - runtimeInputs = [ self'.packages.osrm-backend ]; + runtimeInputs = [ patched-osrm-backend ]; text = '' set -x osrm-routed --algorithm mld \