How to Install GraphHopper on NixOS Latest

GraphHopper is an open-source routing engine that is used to calculate road or path routes. This tutorial explains the steps to install GraphHopper on NixOS Latest.

Prerequisites

Installation

  1. Open a terminal and navigate to the GraphHopper website https://graphhopper.com/.

  2. Click on the Download option, a page with the download links will appear. Choose the latest version that supports the NixOS platform.

  3. Once the download is complete open the terminal.

  4. Now, navigate to the directory where you downloaded the GraphHopper application.

    $ cd ~/Downloads
    
  5. Extract the downloaded file

    $ tar -xvf graphhopper-1.4.0.tar.gz
    
  6. Move the extracted directory to a new location

    $ sudo mv graphhopper-1.4.0 /opt
    
  7. Set the environment variable for GraphHopper

    $ export GRAPHHOPPER_DIR=/opt/graphhopper-1.4.0
    
  8. Now, create a GraphHopper service to start GraphHopper on boot

    $ sudo vim /etc/nixos/configuration.nix
    
  9. Add the following code in the configuration file

    ...
    services.graphhopper = {
      enable = true;
      dataDir = "/opt/graphhopper-1.4.0/data";
      configFile = "/opt/graphhopper-1.4.0/config-example.yml";
      cmd = "${GRAPHHOPPER_DIR}/graphhopper.sh start";
    };
    ...
    

    (Note: Ensure all of these files/subdirectories exist, otherwise you may encounter errors. If user doesn't have permission to create this directory, it's best to symlink to a directory the user owns. For example, /mnt/data/graphhopper-1.4.0/data)

  10. Now, create a symlink for the GraphHopper service

    $ sudo ln -s /etc/nixos/configuration.nix /etc/nixos/$(uname --nodename).nix
    
  11. Redeploy NixOS

    $ sudo nixos-rebuild switch
    
  12. Start the GraphHopper service

    $ sudo systemctl start graphhopper
    
  13. Test the GraphHopper service

    http://localhost:8989
    

You have successfully installed and configured GraphHopper on NixOS Latest OS. Now, you can use it to calculate road or path routes for your maps.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!