summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorJakob Gillich <jakob@gillich.me>2015-12-08 10:40:43 +0100
committerJakob Gillich <jakob@gillich.me>2015-12-09 00:28:41 +0100
commit29871ee2ddfb940b37ee697ce5d2e8ce85337305 (patch)
tree61974063e329737a111daac94a744c16056ea92a /nixos/modules
parent27bea9a3aad18d3512683d5c017b851efc0dbe05 (diff)
downloadnixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar.gz
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar.bz2
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar.lz
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar.xz
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.tar.zst
nixlib-29871ee2ddfb940b37ee697ce5d2e8ce85337305.zip
miniupnpd: add service
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/networking/miniupnpd.nix70
2 files changed, 71 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 9fc1d54bd842..744857c5901c 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -312,6 +312,7 @@
   ./services/networking/lambdabot.nix
   ./services/networking/mailpile.nix
   ./services/networking/minidlna.nix
+  ./services/networking/miniupnpd.nix
   ./services/networking/mstpd.nix
   ./services/networking/murmur.nix
   ./services/networking/namecoind.nix
diff --git a/nixos/modules/services/networking/miniupnpd.nix b/nixos/modules/services/networking/miniupnpd.nix
new file mode 100644
index 000000000000..e654eb80b177
--- /dev/null
+++ b/nixos/modules/services/networking/miniupnpd.nix
@@ -0,0 +1,70 @@
+{ 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 = {
+      enable = mkEnableOption "MiniUPnP daemon";
+
+      externalInterface = mkOption {
+        type = types.str;
+        description = ''
+          Name of the external interface.
+        '';
+      };
+
+      internalIPs = mkOption {
+        type = types.listOf types.str;
+        example = [ "192.168.1.0/24" ];
+        description = ''
+          The IP address ranges to listen on.
+        '';
+      };
+
+      natpmp = mkEnableOption "NAT-PMP support";
+
+      upnp = mkOption {
+        default = true;
+        type = types.bool;
+        description = ''
+          Whether to enable UPNP support.
+        '';
+      };
+
+      appendConfig = mkOption {
+        type = types.lines;
+        default = "";
+        description = ''
+          Configuration lines appended to the MiniUPnP config.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.miniupnpd = {
+      description = "MiniUPnP daemon";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+      path = [ pkgs.miniupnpd ];
+      serviceConfig = {
+        ExecStart = "${pkgs.miniupnpd}/bin/miniupnpd -d -f ${configFile}";
+      };
+    };
+  };
+}