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