1 { config, lib, pkgs, ... }:
6 cfg = config.services.miniupnpd;
7 configFile = pkgs.writeText "miniupnpd.conf" ''
8 ext_ifname=${cfg.externalInterface}
9 enable_natpmp=${if cfg.natpmp then "yes" else "no"}
10 enable_upnp=${if cfg.upnp then "yes" else "no"}
12 ${concatMapStrings (range: ''
21 services.miniupnpd = {
22 enable = mkEnableOption (lib.mdDoc "MiniUPnP daemon");
24 externalInterface = mkOption {
26 description = lib.mdDoc ''
27 Name of the external interface.
31 internalIPs = mkOption {
32 type = types.listOf types.str;
33 example = [ "192.168.1.1/24" "enp1s0" ];
34 description = lib.mdDoc ''
35 The IP address ranges to listen on.
39 natpmp = mkEnableOption (lib.mdDoc "NAT-PMP support");
44 description = lib.mdDoc ''
45 Whether to enable UPNP support.
49 appendConfig = mkOption {
52 description = lib.mdDoc ''
53 Configuration lines appended to the MiniUPnP config.
59 config = mkIf cfg.enable {
60 networking.firewall.extraCommands = ''
61 ${pkgs.bash}/bin/bash -x ${pkgs.miniupnpd}/etc/miniupnpd/iptables_init.sh -i ${cfg.externalInterface}
64 networking.firewall.extraStopCommands = ''
65 ${pkgs.bash}/bin/bash -x ${pkgs.miniupnpd}/etc/miniupnpd/iptables_removeall.sh -i ${cfg.externalInterface}
68 systemd.services.miniupnpd = {
69 description = "MiniUPnP daemon";
70 after = [ "network.target" ];
71 wantedBy = [ "multi-user.target" ];
73 ExecStart = "${pkgs.miniupnpd}/bin/miniupnpd -f ${configFile}";
74 PIDFile = "/run/miniupnpd.pid";