about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/networking/scion/scion-dispatcher.nix
blob: bab1ec0a989b5fca37cdfc8b0218eeb3818166bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.scion.scion-dispatcher;
  toml = pkgs.formats.toml { };
  defaultConfig = {
    dispatcher = {
      id = "dispatcher";
      socket_file_mode = "0770";
      application_socket = "/dev/shm/dispatcher/default.sock";
    };
    log.console = {
      level = "info";
    };
  };
  configFile = toml.generate "scion-dispatcher.toml" (defaultConfig // cfg.settings);
in
{
  options.services.scion.scion-dispatcher = {
    enable = mkEnableOption (lib.mdDoc "the scion-dispatcher service");
    settings = mkOption {
      default = { };
      type = toml.type;
      example = literalExpression ''
        {
          dispatcher = {
            id = "dispatcher";
            socket_file_mode = "0770";
            application_socket = "/dev/shm/dispatcher/default.sock";
          };
          log.console = {
            level = "info";
          };
        }
      '';
      description = lib.mdDoc ''
        scion-dispatcher configuration. Refer to
        <https://docs.scion.org/en/latest/manuals/common.html>
        for details on supported values.
      '';
    };
  };
  config = mkIf cfg.enable {
    # Needed for group ownership of the dispatcher socket
    users.groups.scion = {};

    # scion programs hardcode path to dispatcher in /run/shm, and is not
    # configurable at runtime upstream plans to obsolete the dispatcher in
    # favor of an SCMP daemon, at which point this can be removed.
    system.activationScripts.scion-dispatcher = ''
      ln -sf /dev/shm /run/shm
    '';

    systemd.services.scion-dispatcher = {
      description = "SCION Dispatcher";
      after = [ "network-online.target" ];
      wants = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "simple";
        Group = "scion";
        DynamicUser = true;
        BindPaths = [ "/dev/shm:/run/shm" ];
        ExecStartPre = "${pkgs.coreutils}/bin/rm -rf /run/shm/dispatcher";
        ExecStart = "${pkgs.scion}/bin/scion-dispatcher --config ${configFile}";
        Restart = "on-failure";
        StateDirectory = "scion-dispatcher";
      };
    };
  };
}