{ config, lib, pkgs, ... }:

let
  cfg = config.samfelag.modules.system.tailscale;
in
{
  options.samfelag.modules.system.tailscale = {
    enable = lib.mkEnableOption "tailscale";
  };
  config = lib.mkIf cfg.enable {
    # See https://github.com/tailscale/tailscale/issues/4432
    networking = {
      firewall.checkReversePath = "loose";
      nameservers = [ "100.99.167.21" ];
      networkmanager.dns = "none";
    };
    services.tailscale.enable = true;
  };
}
