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-router;
13 toml = pkgs.formats.toml { };
14 defaultConfig = {
15 general = {
16 id = "br";
17 config_dir = "/etc/scion";
18 };
19 };
20 configFile = toml.generate "scion-router.toml" (recursiveUpdate defaultConfig cfg.settings);
21in
22{
23 options.services.scion.scion-router = {
24 enable = mkEnableOption "the scion-router service";
25 settings = mkOption {
26 default = { };
27 type = toml.type;
28 example = literalExpression ''
29 {
30 general.id = "br";
31 }
32 '';
33 description = ''
34 scion-router configuration. Refer to
35 <https://docs.scion.org/en/latest/manuals/common.html>
36 for details on supported values.
37 '';
38 };
39 };
40 config = mkIf cfg.enable {
41 systemd.services.scion-router = {
42 description = "SCION Router";
43 after = [ "network-online.target" ];
44 wants = [ "network-online.target" ];
45 wantedBy = [ "multi-user.target" ];
46 serviceConfig = {
47 Type = "simple";
48 ExecStart = "${globalCfg.package}/bin/scion-router --config ${configFile}";
49 Restart = "on-failure";
50 DynamicUser = true;
51 ${if globalCfg.stateless then "RuntimeDirectory" else "StateDirectory"} = "scion-router";
52 };
53 };
54 };
55}