1
0

Replace redundant statement with function generator

This commit is contained in:
clerie 2020-12-26 22:11:22 +01:00
parent ea5739ae2a
commit 06625139dd

View File

@ -5,23 +5,19 @@ with lib;
let
cfg = config.clerie.nginx-port-forward;
mkServerBlock = isUDP: port: forward: ''
server {
listen ${port}${optionalString isUDP " udp"};
listen [::]:${port}${optionalString isUDP " udp"};
proxy_pass ${forward.host}:${toString forward.port};
}
'';
portForwardConf = ''
stream {
${ concatStringsSep "\n" ( mapAttrsToList ( port: forward: ''
server {
listen ${port};
listen [::]:${port};
proxy_pass ${forward.host}:${toString forward.port};
stream {
${ concatStringsSep "\n" (mapAttrsToList (mkServerBlock false) cfg.tcpPorts) }
${ concatStringsSep "\n" (mapAttrsToList (mkServerBlock true) cfg.udpPorts) }
}
'' ) cfg.tcpPorts ) }
${ concatStringsSep "\n" ( mapAttrsToList ( port: forward: ''
server {
listen ${port} udp;
listen [::]:${port} udp;
proxy_pass ${forward.host}:${toString forward.port};
}
'' ) cfg.udpPorts ) }
}
'';
portOpts = { config, ... }@moduleAttrs: {