Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/feat/nammayatr-custom-osrm-backend #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading