From 386ecf3d14ea486aba523b14200fcd2e7e04b9d6 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Thu, 13 Feb 2025 16:54:19 -0500 Subject: nixos: make more "traits" mixins --- modules/nixos/mixins/tailscale.nix | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/nixos/mixins/tailscale.nix (limited to 'modules/nixos/mixins/tailscale.nix') diff --git a/modules/nixos/mixins/tailscale.nix b/modules/nixos/mixins/tailscale.nix new file mode 100644 index 0000000..177aa90 --- /dev/null +++ b/modules/nixos/mixins/tailscale.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + ... +}: + +let + cfg = config.services.tailscale; + + usingTailscaleSSH = lib.elem "--ssh" config.services.tailscale.extraUpFlags; +in + +{ + config = lib.mkMerge [ + { + services.tailscale = { + openFirewall = true; + }; + } + + (lib.mkIf cfg.enable { + networking.firewall = { + # Trust all connections over Tailscale + trustedInterfaces = [ config.services.tailscale.interfaceName ]; + }; + }) + + (lib.mkIf (cfg.enable && usingTailscaleSSH) { + networking.firewall = { + allowedTCPPorts = [ 22 ]; + }; + }) + ]; +} -- cgit v1.2.3