Replace redundant statement with function generator
This commit is contained in:
parent
ea5739ae2a
commit
06625139dd
@ -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: {
|
||||
|
Loading…
Reference in New Issue
Block a user