ports: make upnp service files more human-readable

This commit is contained in:
Colin 2023-08-31 01:02:31 +00:00
parent 9fea007d4f
commit ff39fc5d95

View File

@ -46,15 +46,13 @@ let
upnpServiceForPort = port: portCfg: upnpServiceForPort = port: portCfg:
lib.mkIf portCfg.visibleTo.wan { lib.mkIf portCfg.visibleTo.wan {
"upnp-forward-${port}" = { "upnp-forward-${port}" = {
description = "forward port ${port} from upstream gateway to this host"; description = "forward port ${port} (${portCfg.description}) from upstream gateway to this host";
restartTriggers = [(builtins.toJSON portCfg)]; restartTriggers = [(builtins.toJSON portCfg)];
serviceConfig.Type = "oneshot"; serviceConfig = {
serviceConfig.TimeoutSec = "6min"; Type = "oneshot";
TimeoutSec = "6min";
after = [ "network.target" ]; ExecStart =
wantedBy = [ "upnp-forwards.target" ];
script =
let let
portFwd = "${pkgs.sane-scripts.ip-port-forward}/bin/sane-ip-port-forward"; portFwd = "${pkgs.sane-scripts.ip-port-forward}/bin/sane-ip-port-forward";
forwards = lib.flatten [ forwards = lib.flatten [
@ -65,6 +63,10 @@ let
${portFwd} -v -d ${builtins.toString cfg.upnpLeaseDuration} \ ${portFwd} -v -d ${builtins.toString cfg.upnpLeaseDuration} \
${lib.escapeShellArgs forwards} ${lib.escapeShellArgs forwards}
''; '';
};
after = [ "network.target" ];
wantedBy = [ "upnp-forwards.target" ];
}; };
}; };
in in