nixos-config/services/tailscale.nix

37 lines
769 B
Nix
Raw Normal View History

2021-07-13 23:48:41 +02:00
{ config, lib, pkgs, ... }:
let
2022-01-11 16:08:21 +01:00
inherit (lib)
mkEnableOption
mkIf
;
2021-07-13 23:48:41 +02:00
cfg = config.my.services.tailscale;
in
{
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 = {
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
};
# 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;
};
};
}