aboutsummaryrefslogtreecommitdiffstats
path: root/modules/nixos/sils/tailscale.nix
blob: e1f49a453862b18d021756fc05def2d6cd584e23 (plain) (blame)
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
46
47
48
49
50
51
52
{
  config,
  lib,
  ...
}: let
  cfg = config.sils.tailscale;
in {
  options.sils.tailscale = {
    enable = lib.mkEnableOption "Tailscale";
    openFirewall = true;
    role = lib.mkOption {
      type = lib.types.enum [
        "client"
        "server"
      ];
    };
  };
  config = lib.mkIf cfg.enable {
    services.tailscale = {
      enable = true;
      authKeyFile = config.age.secrets.tailscale.path;
      useRoutingFeatures = cfg.role;
      extraDaemonFlags = [
        "--no-logs-no-support"
      ];
      extraSetFlags = [
        "--accept-routes"
      ];
    };
    networking.firewall = {
      trustedInterfaces = ["tailscale0"];
      allowedUDPPorts = [config.services.tailscale.port];
      checkReversePath = "loose";
    };
    systemd = {
      services.tailscaled.serviceConfig.Environment = [
        "TS_DEBUG_FIREWALL_MODE=nftables"
      ];
      network.wait-online.enable = false;
    };
    boot.initrd.systemd.network.wait-online.enable = false;

    environment.persistence."/srv".directories = [
      {
        directory = "/var/lib/tailscale";
        user = "root";
        group = "root";
        mode = "0700";
      }
    ];
  };
}