summaryrefslogtreecommitdiff
path: root/machines/biski/portforward.nix
blob: a2fd58abb587e22bfa097da6ae5a7fedd152cd74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{ config, lib, ... }: {
  networking = let
    forward_ports = [
      25565
      25566
    ];
    forward_protocols = [ "tcp" "udp" ];
    internal_ip = "100.64.0.2";
  in {
    firewall = {
      enable = true;
      allowedUDPPorts = forward_ports;
      allowedTCPPorts = forward_ports;
    };
    nat = {
      enable = true;
      internalInterfaces = [ "tailscale0" ];
      externalInterface = "eno1";

      forwardPorts = builtins.concatLists (
        lib.lists.forEach forward_protocols (protocol:
          builtins.concatMap (port: [
            {
              destination = "${internal_ip}:${toString port}";
              proto = protocol;
              sourcePort = port;
            }
          ]) forward_ports
        )
      );
    };
    nftables = {
      enable = true;
      flushRuleset = true;
      tables.nixos-nat = {
        family = "ip";
        content = ''
          chain post {
            masquerade
          }
        '';
      };
    };
  };
}