nixos-config/services/tailscale.nix

42 lines
868 B
Nix
Raw Normal View History

2022-04-10 11:54:58 +02:00
{
config,
lib,
pkgs,
...
}: let
inherit
(lib)
2022-01-11 16:08:21 +01:00
mkEnableOption
mkIf
2022-04-10 11:54:58 +02:00
;
2022-01-11 16:08:21 +01:00
2021-07-13 23:48:41 +02:00
cfg = config.my.services.tailscale;
2022-04-10 11:54:58 +02:00
in {
2021-07-13 23:48:41 +02:00
options.my.services.tailscale = {
2022-01-11 16:08:21 +01:00
enable = mkEnableOption "Tailscale";
# NOTE: still have to do `tailscale up --advertise-exit-node`
2022-01-11 16:08:21 +01:00
exitNode = mkEnableOption "Use as exit node";
2021-07-13 23:48:41 +02:00
};
config = mkIf cfg.enable {
services.tailscale = {
enable = true;
package = pkgs.tailscale;
2021-07-13 23:48:41 +02:00
};
networking.firewall = {
2022-04-10 11:54:58 +02:00
trustedInterfaces = ["tailscale0"];
allowedUDPPorts = [config.services.tailscale.port];
# needed for exit node usage
checkReversePath = mkIf (!cfg.exitNode) "loose";
2021-07-13 23:48:41 +02:00
};
# enable IP forwarding to use as exit node
boot.kernel.sysctl = mkIf cfg.exitNode {
2021-07-13 23:48:41 +02:00
"net.ipv6.conf.all.forwarding" = true;
"net.ipv4.ip_forward" = true;
};
};
}