Skip to content

Commit

Permalink
Backend/feat/nammayatr-custom-osrm-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilesh Bhadauriya committed Nov 11, 2024
1 parent 1a7305b commit 2fded55
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 23 deletions.
18 changes: 18 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}
}
82 changes: 61 additions & 21 deletions osrm.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ inputs, ... }:
{ osrmBackend, inputs, ... }:

let
openStreetDataFileName = "india-latest";
Expand All @@ -11,31 +11,71 @@ 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
cp ${carLuaPath} $out/profiles/car.lua
'';
patched-osrm-backend = pkgs.osrm-backend.overrideAttrs (oldAttrs: {
src = osrmBackend;
});
# 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 = [ patched-osrm-backend ]; }
''
mkdir -p $out && cd $out
# Link input files
ln -s ${inputs.india-latest} ${openStreetDataFileName}.osm.pbf
ln -s ${speedDataPath} ${indiaSpeedDataFileName}.csv
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
'';
# 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 \
Expand Down

0 comments on commit 2fded55

Please sign in to comment.