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";
|
2021-07-14 00:08:40 +02:00
|
|
|
|
|
|
|
# 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;
|
2021-08-19 23:34:41 +02:00
|
|
|
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];
|
2022-05-15 19:45:42 +02:00
|
|
|
# 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
|
2021-07-14 00:08:40 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|