1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.osrm;
7in
8
9{
10 options.services.osrm = {
11 enable = mkOption {
12 type = types.bool;
13 default = false;
14 description = "Enable the OSRM service.";
15 };
16
17 address = mkOption {
18 type = types.str;
19 default = "0.0.0.0";
20 description = "IP address on which the web server will listen.";
21 };
22
23 port = mkOption {
24 type = types.int;
25 default = 5000;
26 description = "Port on which the web server will run.";
27 };
28
29 threads = mkOption {
30 type = types.int;
31 default = 4;
32 description = "Number of threads to use.";
33 };
34
35 algorithm = mkOption {
36 type = types.enum [ "CH" "CoreCH" "MLD" ];
37 default = "MLD";
38 description = "Algorithm to use for the data. Must be one of CH, CoreCH, MLD";
39 };
40
41 extraFlags = mkOption {
42 type = types.listOf types.str;
43 default = [];
44 example = [ "--max-table-size 1000" "--max-matching-size 1000" ];
45 description = "Extra command line arguments passed to osrm-routed";
46 };
47
48 dataFile = mkOption {
49 type = types.path;
50 example = "/var/lib/osrm/berlin-latest.osrm";
51 description = "Data file location";
52 };
53
54 };
55
56 config = mkIf cfg.enable {
57
58 users.users.osrm = {
59 group = config.users.users.osrm.name;
60 description = "OSRM user";
61 createHome = false;
62 };
63
64 users.groups.osrm = { };
65
66 systemd.services.osrm = {
67 description = "OSRM service";
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
70
71 serviceConfig = {
72 User = config.users.extraUsers.osrm.name;
73 ExecStart = ''
74 ${pkgs.osrm-backend}/bin/osrm-routed \
75 --ip ${cfg.address} \
76 --port ${toString cfg.port} \
77 --threads ${toString cfg.threads} \
78 --algorithm ${cfg.algorithm} \
79 ${toString cfg.extraFlags} \
80 ${cfg.dataFile}
81 '';
82 };
83 };
84 };
85}