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