|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + utils, |
| 6 | + ... |
| 7 | +}: |
| 8 | +let |
| 9 | + inherit (lib) |
| 10 | + filterAttrsRecursive |
| 11 | + getExe |
| 12 | + maintainers |
| 13 | + mkEnableOption |
| 14 | + mkPackageOption |
| 15 | + mkOption |
| 16 | + types |
| 17 | + ; |
| 18 | + inherit (utils) escapeSystemdExecArgs; |
| 19 | + cfg = config.services.routinator; |
| 20 | + settingsFormat = pkgs.formats.toml { }; |
| 21 | +in |
| 22 | +{ |
| 23 | + options.services.routinator = { |
| 24 | + enable = mkEnableOption "Routinator 3000"; |
| 25 | + |
| 26 | + package = mkPackageOption pkgs "routinator" { }; |
| 27 | + |
| 28 | + extraArgs = mkOption { |
| 29 | + description = '' |
| 30 | + Extra arguments passed to routinator, see <https://routinator.docs.nlnetlabs.nl/en/stable/manual-page.html#options> for options."; |
| 31 | + ''; |
| 32 | + type = types.listOf types.str; |
| 33 | + default = [ ]; |
| 34 | + example = [ "--no-rir-tals" ]; |
| 35 | + }; |
| 36 | + |
| 37 | + extraServerArgs = mkOption { |
| 38 | + description = '' |
| 39 | + Extra arguments passed to the server subcommand, see <https://routinator.docs.nlnetlabs.nl/en/stable/manual-page.html#subcmd-server> for options."; |
| 40 | + ''; |
| 41 | + type = types.listOf types.str; |
| 42 | + default = [ ]; |
| 43 | + example = [ "--rtr-client-metrics" ]; |
| 44 | + }; |
| 45 | + |
| 46 | + settings = mkOption { |
| 47 | + type = types.submodule { |
| 48 | + freeformType = settingsFormat.type; |
| 49 | + options = { |
| 50 | + repository-dir = mkOption { |
| 51 | + type = types.path; |
| 52 | + description = '' |
| 53 | + The path where the collected RPKI data is stored. |
| 54 | + ''; |
| 55 | + default = "/var/lib/routinator/rpki-cache"; |
| 56 | + }; |
| 57 | + log-level = mkOption { |
| 58 | + type = types.nullOr ( |
| 59 | + types.enum [ |
| 60 | + "error" |
| 61 | + "warn" |
| 62 | + "info" |
| 63 | + "debug" |
| 64 | + ] |
| 65 | + ); |
| 66 | + description = '' |
| 67 | + A string value specifying the maximum log level for which log messages should be emitted. |
| 68 | + See, <https://routinator.docs.nlnetlabs.nl/en/stable/manual-page.html#logging> |
| 69 | + ''; |
| 70 | + default = "warn"; |
| 71 | + }; |
| 72 | + log = mkOption { |
| 73 | + type = types.nullOr ( |
| 74 | + types.enum [ |
| 75 | + "default" |
| 76 | + "stderr" |
| 77 | + "syslog" |
| 78 | + "file" |
| 79 | + ] |
| 80 | + ); |
| 81 | + description = '' |
| 82 | + A string specifying where to send log messages to. |
| 83 | + See, <https://routinator.docs.nlnetlabs.nl/en/stable/manual-page.html#term-log> |
| 84 | + ''; |
| 85 | + default = "default"; |
| 86 | + }; |
| 87 | + log-file = mkOption { |
| 88 | + type = types.nullOr types.path; |
| 89 | + description = '' |
| 90 | + A string value containing the path to a file to which log messages will be appended if the log configuration value is set to file. In this case, the value is mandatory. |
| 91 | + ''; |
| 92 | + default = null; |
| 93 | + }; |
| 94 | + http-listen = mkOption { |
| 95 | + type = types.nullOr (types.listOf types.str); |
| 96 | + description = '' |
| 97 | + An array of string values each providing an address and port on which the HTTP server should listen. Address and port should be separated by a colon. IPv6 address should be enclosed in square brackets. |
| 98 | + ''; |
| 99 | + default = null; |
| 100 | + }; |
| 101 | + rtr-listen = mkOption { |
| 102 | + type = types.nullOr (types.listOf types.str); |
| 103 | + description = '' |
| 104 | + An array of string values each providing an address and port on which the RTR server should listen in TCP mode. Address and port should be separated by a colon. IPv6 address should be enclosed in square brackets. |
| 105 | + ''; |
| 106 | + default = null; |
| 107 | + }; |
| 108 | + refresh = mkOption { |
| 109 | + type = types.nullOr types.int; |
| 110 | + description = '' |
| 111 | + An integer value specifying the number of seconds Routinator should wait between consecutive validation runs in server mode. The next validation run will happen earlier, if objects expire earlier. |
| 112 | + ''; |
| 113 | + default = 600; |
| 114 | + }; |
| 115 | + retry = mkOption { |
| 116 | + type = types.nullOr types.int; |
| 117 | + description = '' |
| 118 | + An integer value specifying the number of seconds an RTR client is requested to wait after it failed to receive a data set. |
| 119 | + ''; |
| 120 | + default = 600; |
| 121 | + }; |
| 122 | + expire = mkOption { |
| 123 | + type = types.nullOr types.int; |
| 124 | + description = '' |
| 125 | + An integer value specifying the number of seconds an RTR client is requested to use a data set if it cannot get an update before throwing it away and continuing with no data at all. |
| 126 | + ''; |
| 127 | + default = 7200; |
| 128 | + }; |
| 129 | + }; |
| 130 | + }; |
| 131 | + description = '' |
| 132 | + Configuration for Routinator 3000, see <https://routinator.docs.nlnetlabs.nl/en/stable/manual-page.html#configuration-file> for options. |
| 133 | + ''; |
| 134 | + default = { }; |
| 135 | + }; |
| 136 | + }; |
| 137 | + |
| 138 | + config = { |
| 139 | + systemd.services.routinator = { |
| 140 | + description = "Routinator 3000 is free, open-source RPKI Relying Party software made by NLnet Labs."; |
| 141 | + wantedBy = [ "multi-user.target" ]; |
| 142 | + after = [ "network.target" ]; |
| 143 | + path = with pkgs; [ rsync ]; |
| 144 | + serviceConfig = { |
| 145 | + Type = "exec"; |
| 146 | + ExecStart = escapeSystemdExecArgs ( |
| 147 | + [ |
| 148 | + (getExe cfg.package) |
| 149 | + "--config=${ |
| 150 | + settingsFormat.generate "routinator.conf" (filterAttrsRecursive (n: v: v != null) cfg.settings) |
| 151 | + }" |
| 152 | + ] |
| 153 | + ++ cfg.extraArgs |
| 154 | + ++ [ |
| 155 | + "server" |
| 156 | + ] |
| 157 | + ++ cfg.extraServerArgs |
| 158 | + ); |
| 159 | + Restart = "on-failure"; |
| 160 | + CapabilityBoundingSet = [ "" ]; |
| 161 | + DynamicUser = true; |
| 162 | + LockPersonality = true; |
| 163 | + MemoryDenyWriteExecute = true; |
| 164 | + NoNewPrivileges = true; |
| 165 | + PrivateDevices = true; |
| 166 | + PrivateTmp = true; |
| 167 | + ProtectClock = true; |
| 168 | + ProtectControlGroups = true; |
| 169 | + ProtectHome = true; |
| 170 | + ProtectHostname = true; |
| 171 | + ProtectKernelLogs = true; |
| 172 | + ProtectKernelModules = true; |
| 173 | + ProtectKernelTunables = true; |
| 174 | + ProtectSystem = "strict"; |
| 175 | + RestrictAddressFamilies = [ |
| 176 | + "AF_INET" |
| 177 | + "AF_INET6" |
| 178 | + "AF_UNIX" |
| 179 | + ]; |
| 180 | + RestrictNamespaces = true; |
| 181 | + RestrictRealtime = true; |
| 182 | + StateDirectory = "routinator"; |
| 183 | + SystemCallArchitectures = "native"; |
| 184 | + SystemCallErrorNumber = "EPERM"; |
| 185 | + SystemCallFilter = "@system-service"; |
| 186 | + UMask = "0027"; |
| 187 | + }; |
| 188 | + }; |
| 189 | + }; |
| 190 | + |
| 191 | + meta.maintainers = with maintainers; [ xgwq ]; |
| 192 | +} |
0 commit comments