Skip to content
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: 16 additions & 2 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ on:
branches:
- "main"
workflow_dispatch:


permissions:
contents: write
pull-requests: write
issues: read
packages: write


jobs:
cleanup:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Cleanup old container images
uses: snok/container-retention-policy@v3.0.0
with:
account: ${{ github.repository_owner }}
token: ${{ secrets.GITHUB_TOKEN }}
image-names: ${{ github.event.repository.name }}
cut-off: 1m
keep-n-most-recent: 2
dry-run: false

build:
runs-on: ${{ matrix.os }}
needs: cleanup
if: always()
strategy:
matrix:
os: [x86_64-linux]
Expand Down
18 changes: 9 additions & 9 deletions docker.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{ self, ... }:
let
imageName = "ghcr.io/nammayatri/osrm-builder";
imageTag = builtins.substring 0 6 (self.rev or "dev");
imageTag = builtins.substring 0 6 (self.rev or "dev");
in
{
perSystem = { self', pkgs, lib, ... }: {
packages = {
dockerImage = pkgs.dockerTools.buildImage {
name = imageName;
tag = imageTag;
name = imageName;
tag = imageTag;
created = "now";

# pull in everything under / via buildEnv
copyToRoot = pkgs.buildEnv {
name = "patched-osrm-backend";
name = "osrm-data";
paths = with pkgs; [
cacert
coreutils
bashInteractive
self'.packages.patched-osrm-backend
self'.packages.osrm-server
self'.packages.osrm-data
];
/* pathsToLink = [
"/bin"
"/opt"
];
*/
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion flake.lock

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

108 changes: 66 additions & 42 deletions osrm.nix
Original file line number Diff line number Diff line change
@@ -1,52 +1,76 @@
{ inputs, ... }:

let
openStreetDataFileName = "india-latest";
carLuaPath = ./car.lua; # Adjust this path as needed
speedDataPath = ./speed-data.csv;
indiaSpeedDataFileName = "india-latest-speed-data";
openStreetDataFileName = "india-latest";
carLuaPath = ./car.lua;
speedDataPath = ./speed-data.csv;
indiaSpeedDataFileName = "india-latest-speed-data";
in
{
perSystem = { self', pkgs, lib, ... }: {
packages =
rec {
patched-osrm-backend = pkgs.stdenv.mkDerivation {
name = "patched-osrm-backend";
src = inputs.osrm-backend;
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
];
packages = rec {
# 1) Build your custom OSRM backend via CMake
patched-osrm-backend = pkgs.stdenv.mkDerivation {
name = "patched-osrm-backend";
src = inputs.osrm-backend;
buildInputs = [
pkgs.cmake
pkgs.boost
pkgs.tbb_2021_8
pkgs.expat
pkgs.bzip2
pkgs.libzip
pkgs.pkg-config
pkgs.lua5_2
];
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
mkdir build && cd build
cmake .. \
-DENABLE_MASON=ON \
-DENABLE_IPO=OFF \
-DTBB_ROOT=${pkgs.tbb_2021_8} \
-DCMAKE_PREFIX_PATH="${pkgs.boost};${pkgs.tbb_2021_8};${pkgs.expat};${pkgs.bzip2};${pkgs.lua5_2}" \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS="-std=c++20 -Wno-error=array-bounds -fpermissive" \
-DCMAKE_INSTALL_PREFIX=$out
make
'';
installPhase = ''
mkdir -p $out/bin $out/profiles
cp osrm-* $out/bin/
cp -r ../profiles/* $out/profiles/
cp ${carLuaPath} $out/profiles/car.lua
'';
};

# 2) Generate .osrm.* data under /opt/osrm-data
osrm-data = pkgs.runCommandNoCC "osrm-data" {
buildInputs = [ patched-osrm-backend ];
} ''
# create the same path your k8s command uses
mkdir -p $out/opt/osrm-data
cd $out/opt/osrm-data

ln -s ${inputs.india-latest} ${openStreetDataFileName}.osm.pbf
ln -s ${speedDataPath} ${indiaSpeedDataFileName}.csv

${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
'';

phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
mkdir build
cd build
cmake .. \
-DENABLE_MASON=ON \
-DENABLE_IPO=OFF \
-DTBB_ROOT=${pkgs.tbb_2021_8} \
-DCMAKE_PREFIX_PATH="${pkgs.boost};${pkgs.tbb_2021_8};${pkgs.expat};${pkgs.bzip2};${pkgs.lua5_2}" \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS="-std=c++20 -Wno-error=array-bounds -fpermissive" \
-DCMAKE_INSTALL_PREFIX=$out
make
'';
installPhase = ''
mkdir -p $out/bin $out/profiles
cp osrm-* $out/bin/

cp -r ../profiles/* $out/profiles/

cp ${carLuaPath} $out/profiles/car.lua
'';
};
# 3) Wrapper pointing at the /opt directory
osrm-server = pkgs.writeShellApplication {
name = "osrm-server";
runtimeInputs = [ patched-osrm-backend ];
text = ''
set -x
osrm-routed --algorithm mld /opt/osrm-data/${openStreetDataFileName}.osrm
'';
};
};
};
}