summaryrefslogtreecommitdiff
path: root/modules/nixos/mixins/tailscale.nix
blob: 177aa9050480c48d518a74302d48109fd0254783 (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
{
  config,
  lib,
  ...
}:

let
  cfg = config.services.tailscale;

  usingTailscaleSSH = lib.elem "--ssh" config.services.tailscale.extraUpFlags;
in

{
  config = lib.mkMerge [
    {
      services.tailscale = {
        openFirewall = true;
      };
    }

    (lib.mkIf cfg.enable {
      networking.firewall = {
        # Trust all connections over Tailscale
        trustedInterfaces = [ config.services.tailscale.interfaceName ];
      };
    })

    (lib.mkIf (cfg.enable && usingTailscaleSSH) {
      networking.firewall = {
        allowedTCPPorts = [ 22 ];
      };
    })
  ];
}