at master 2.2 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8with lib; 9 10let 11 globalCfg = config.services.scion; 12 cfg = config.services.scion.scion-dispatcher; 13 toml = pkgs.formats.toml { }; 14 defaultConfig = { 15 dispatcher = { 16 id = "dispatcher"; 17 local_udp_forwarding = true; 18 }; 19 log.console = { 20 level = "info"; 21 }; 22 }; 23 configFile = toml.generate "scion-dispatcher.toml" (recursiveUpdate defaultConfig cfg.settings); 24in 25{ 26 options.services.scion.scion-dispatcher = { 27 enable = mkEnableOption "the scion-dispatcher service"; 28 settings = mkOption { 29 default = { }; 30 type = toml.type; 31 example = literalExpression '' 32 { 33 dispatcher = { 34 id = "dispatcher"; 35 socket_file_mode = "0770"; 36 application_socket = "/dev/shm/dispatcher/default.sock"; 37 }; 38 log.console = { 39 level = "info"; 40 }; 41 } 42 ''; 43 description = '' 44 scion-dispatcher configuration. Refer to 45 <https://docs.scion.org/en/latest/manuals/common.html> 46 for details on supported values. 47 ''; 48 }; 49 }; 50 config = mkIf cfg.enable { 51 # Needed for group ownership of the dispatcher socket 52 users.groups.scion = { }; 53 54 # scion programs hardcode path to dispatcher in /run/shm, and is not 55 # configurable at runtime upstream plans to obsolete the dispatcher in 56 # favor of an SCMP daemon, at which point this can be removed. 57 system.activationScripts.scion-dispatcher = '' 58 ln -sf /dev/shm /run/shm 59 ''; 60 61 systemd.services.scion-dispatcher = { 62 description = "SCION Dispatcher"; 63 after = [ "network-online.target" ]; 64 wants = [ "network-online.target" ]; 65 wantedBy = [ "multi-user.target" ]; 66 serviceConfig = { 67 Type = "simple"; 68 Group = "scion"; 69 DynamicUser = true; 70 BindPaths = [ "/dev/shm:/run/shm" ]; 71 ExecStartPre = "${pkgs.coreutils}/bin/rm -rf /run/shm/dispatcher"; 72 ExecStart = "${globalCfg.package}/bin/scion-dispatcher --config ${configFile}"; 73 Restart = "on-failure"; 74 ${if globalCfg.stateless then "RuntimeDirectory" else "StateDirectory"} = "scion-dispatcher"; 75 }; 76 }; 77 }; 78}