Replace redundant statement with function generator
This commit is contained in:
parent
ea5739ae2a
commit
06625139dd
@ -5,23 +5,19 @@ 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 ) }
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
portOpts = { config, ... }@moduleAttrs: {
|
portOpts = { config, ... }@moduleAttrs: {
|
||||||
|
Loading…
Reference in New Issue
Block a user