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