at 23.11-pre 2.1 kB view raw
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 = lib.mdDoc "Enable the OSRM service."; 15 }; 16 17 address = mkOption { 18 type = types.str; 19 default = "0.0.0.0"; 20 description = lib.mdDoc "IP address on which the web server will listen."; 21 }; 22 23 port = mkOption { 24 type = types.port; 25 default = 5000; 26 description = lib.mdDoc "Port on which the web server will run."; 27 }; 28 29 threads = mkOption { 30 type = types.int; 31 default = 4; 32 description = lib.mdDoc "Number of threads to use."; 33 }; 34 35 algorithm = mkOption { 36 type = types.enum [ "CH" "CoreCH" "MLD" ]; 37 default = "MLD"; 38 description = lib.mdDoc "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 = lib.mdDoc "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 = lib.mdDoc "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 isSystemUser = true; 63 }; 64 65 users.groups.osrm = { }; 66 67 systemd.services.osrm = { 68 description = "OSRM service"; 69 after = [ "network.target" ]; 70 wantedBy = [ "multi-user.target" ]; 71 72 serviceConfig = { 73 User = config.users.users.osrm.name; 74 ExecStart = '' 75 ${pkgs.osrm-backend}/bin/osrm-routed \ 76 --ip ${cfg.address} \ 77 --port ${toString cfg.port} \ 78 --threads ${toString cfg.threads} \ 79 --algorithm ${cfg.algorithm} \ 80 ${toString cfg.extraFlags} \ 81 ${cfg.dataFile} 82 ''; 83 }; 84 }; 85 }; 86}