vuls: init at 0.27.0
[NixPkgs.git] / nixos / modules / services / networking / scion / scion-control.nix
blob8b6733ac0c2443a9714ff9664e68ef03192c2dc2
1 { config, lib, pkgs, ... }:
3 with lib;
5 let
6   globalCfg = config.services.scion;
7   cfg = config.services.scion.scion-control;
8   toml = pkgs.formats.toml { };
9   connectionDir = if globalCfg.stateless then "/run" else "/var/lib";
10   defaultConfig = {
11     general = {
12       id = "cs";
13       config_dir = "/etc/scion";
14       reconnect_to_dispatcher = true;
15     };
16     beacon_db = {
17       connection = "${connectionDir}/scion-control/control.beacon.db";
18     };
19     path_db = {
20       connection = "${connectionDir}/scion-control/control.path.db";
21     };
22     trust_db = {
23       connection = "${connectionDir}/scion-control/control.trust.db";
24     };
25     log.console = {
26       level = "info";
27     };
28   };
29   configFile = toml.generate "scion-control.toml" (recursiveUpdate defaultConfig cfg.settings);
32   options.services.scion.scion-control = {
33     enable = mkEnableOption "the scion-control service";
34     settings = mkOption {
35       default = { };
36       type = toml.type;
37       example = literalExpression ''
38         {
39           path_db = {
40             connection = "/run/scion-control/control.path.db";
41           };
42           log.console = {
43             level = "info";
44           };
45         }
46       '';
47       description = ''
48         scion-control configuration. Refer to
49         <https://docs.scion.org/en/latest/manuals/common.html>
50         for details on supported values.
51       '';
52     };
53   };
54   config = mkIf cfg.enable {
55     systemd.services.scion-control = {
56       description = "SCION Control Service";
57       after = [ "network-online.target" "scion-dispatcher.service" ];
58       wants = [ "network-online.target" "scion-dispatcher.service" ];
59       wantedBy = [ "multi-user.target" ];
60       serviceConfig = {
61         Type = "simple";
62         Group = if (config.services.scion.scion-dispatcher.enable == true) then "scion" else null;
63         ExecStart = "${globalCfg.package}/bin/scion-control --config ${configFile}";
64         DynamicUser = true;
65         Restart = "on-failure";
66         BindPaths = [ "/dev/shm:/run/shm" ];
67         ${if globalCfg.stateless then "RuntimeDirectory" else "StateDirectory"} = "scion-control";
68       };
69     };
70   };