2015-12-08 09:40:43 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.miniupnpd;
|
|
|
|
configFile = pkgs.writeText "miniupnpd.conf" ''
|
|
|
|
ext_ifname=${cfg.externalInterface}
|
|
|
|
enable_natpmp=${if cfg.natpmp then "yes" else "no"}
|
|
|
|
enable_upnp=${if cfg.upnp then "yes" else "no"}
|
|
|
|
|
|
|
|
${concatMapStrings (range: ''
|
|
|
|
listening_ip=${range}
|
|
|
|
'') cfg.internalIPs}
|
|
|
|
|
|
|
|
${cfg.appendConfig}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.miniupnpd = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "MiniUPnP daemon");
|
2015-12-08 09:40:43 +00:00
|
|
|
|
|
|
|
externalInterface = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-12-08 09:40:43 +00:00
|
|
|
Name of the external interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
internalIPs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2015-12-13 15:43:31 +00:00
|
|
|
example = [ "192.168.1.1/24" "enp1s0" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-12-08 09:40:43 +00:00
|
|
|
The IP address ranges to listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
natpmp = mkEnableOption (lib.mdDoc "NAT-PMP support");
|
2015-12-08 09:40:43 +00:00
|
|
|
|
|
|
|
upnp = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-12-08 09:40:43 +00:00
|
|
|
Whether to enable UPNP support.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
appendConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2015-12-08 09:40:43 +00:00
|
|
|
Configuration lines appended to the MiniUPnP config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2015-12-13 15:43:31 +00:00
|
|
|
networking.firewall.extraCommands = ''
|
2018-09-15 13:08:18 +00:00
|
|
|
${pkgs.bash}/bin/bash -x ${pkgs.miniupnpd}/etc/miniupnpd/iptables_init.sh -i ${cfg.externalInterface}
|
2015-12-13 15:43:31 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
networking.firewall.extraStopCommands = ''
|
2018-09-15 13:08:18 +00:00
|
|
|
${pkgs.bash}/bin/bash -x ${pkgs.miniupnpd}/etc/miniupnpd/iptables_removeall.sh -i ${cfg.externalInterface}
|
2015-12-13 15:43:31 +00:00
|
|
|
'';
|
|
|
|
|
2015-12-08 09:40:43 +00:00
|
|
|
systemd.services.miniupnpd = {
|
|
|
|
description = "MiniUPnP daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2015-12-13 15:43:31 +00:00
|
|
|
ExecStart = "${pkgs.miniupnpd}/bin/miniupnpd -f ${configFile}";
|
2018-12-19 21:40:21 +00:00
|
|
|
PIDFile = "/run/miniupnpd.pid";
|
2015-12-13 15:43:31 +00:00
|
|
|
Type = "forking";
|
2015-12-08 09:40:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|