init natpmp module thing
This commit is contained in:
parent
aec7b8bdde
commit
6c46e5d5a7
3 changed files with 63 additions and 0 deletions
|
|
@ -30,6 +30,7 @@
|
|||
l.nixosSystem {
|
||||
modules = [
|
||||
./hosts/${hostname}
|
||||
./modules/default.nix
|
||||
(
|
||||
if b.pathExists ./secrets/${hostname}
|
||||
then ./secrets/${hostname}
|
||||
|
|
|
|||
5
modules/default.nix
Normal file
5
modules/default.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
imports = [
|
||||
./natpmp-portforward.nix
|
||||
];
|
||||
}
|
||||
57
modules/natpmp-portforward.nix
Normal file
57
modules/natpmp-portforward.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
cfg = config.own.natpmp-portforward;
|
||||
in {
|
||||
options.own.natpmp-portforward = {
|
||||
enable = lib.mkEnableOption "enable natpmp port forwarding service";
|
||||
mappings = lib.types.listOf (lib.types.submodule {
|
||||
options = {
|
||||
public = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
};
|
||||
private = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
};
|
||||
protocol = lib.mkOption {
|
||||
default = "tcp";
|
||||
type = lib.types.enum [
|
||||
"tcp"
|
||||
"udp"
|
||||
];
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.natpmp-portforward = {
|
||||
requisite = ["network-online.target"];
|
||||
serviceConfig = {
|
||||
Restart = "on-failure";
|
||||
ExecStart = pkgs.writeScript "natpmp-portforward" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
|
||||
"${lib.concatMapStrings (x: ''
|
||||
${pkgs.libnatpmp}/bin/natpmpc -a ${x.public} ${x.private} ${x.protocol} 60
|
||||
'')
|
||||
cfg.mappings}"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.natpmp-portforward = {
|
||||
requires = ["network-online.target"];
|
||||
wantedBy = ["timers.target"];
|
||||
timerConfig = {
|
||||
OnBootSec = "1m";
|
||||
OnUnitActiveSec = "1m";
|
||||
AccuracySec = "5s";
|
||||
Unit = "natpmp-portforward.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue