Replace redundant statement with function generator
This commit is contained in:
parent
ea5739ae2a
commit
06625139dd
@ -5,22 +5,18 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.clerie.nginx-port-forward;
|
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 = ''
|
portForwardConf = ''
|
||||||
stream {
|
stream {
|
||||||
${ concatStringsSep "\n" ( mapAttrsToList ( port: forward: ''
|
${ concatStringsSep "\n" (mapAttrsToList (mkServerBlock false) cfg.tcpPorts) }
|
||||||
server {
|
${ concatStringsSep "\n" (mapAttrsToList (mkServerBlock true) cfg.udpPorts) }
|
||||||
listen ${port};
|
|
||||||
listen [::]:${port};
|
|
||||||
proxy_pass ${forward.host}:${toString forward.port};
|
|
||||||
}
|
|
||||||
'' ) cfg.tcpPorts ) }
|
|
||||||
${ concatStringsSep "\n" ( mapAttrsToList ( port: forward: ''
|
|
||||||
server {
|
|
||||||
listen ${port} udp;
|
|
||||||
listen [::]:${port} udp;
|
|
||||||
proxy_pass ${forward.host}:${toString forward.port};
|
|
||||||
}
|
|
||||||
'' ) cfg.udpPorts ) }
|
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user