2024-03-07 20:07:03 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2020-05-22 18:16:21 +02:00
|
|
|
|
2024-01-06 03:06:53 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.tailscale;
|
|
|
|
tailscaleInterface = cfg.interfaceName;
|
2024-01-21 21:40:27 +01:00
|
|
|
inherit (config.networking) hostName;
|
|
|
|
tailnetHost = "${hostName}.tail05275.ts.net";
|
2023-12-27 18:03:57 +01:00
|
|
|
in {
|
2020-11-14 11:20:59 +01:00
|
|
|
networking.wireguard.enable = true;
|
2023-12-27 18:03:57 +01:00
|
|
|
networking.firewall.trustedInterfaces = [ tailscaleInterface ];
|
2021-06-10 12:14:30 +02:00
|
|
|
|
2023-12-27 18:03:57 +01:00
|
|
|
services.tailscale = {
|
|
|
|
enable = true;
|
2024-03-07 20:07:03 +01:00
|
|
|
package = pkgs.unstable.tailscale;
|
2023-12-27 18:03:57 +01:00
|
|
|
openFirewall = true;
|
|
|
|
useRoutingFeatures = "both";
|
2024-01-06 03:06:53 +01:00
|
|
|
extraUpFlags = [
|
|
|
|
"--reset"
|
|
|
|
"--accept-routes"
|
2024-01-12 20:46:03 +01:00
|
|
|
"--exit-node-allow-lan-access"
|
2024-01-06 03:06:53 +01:00
|
|
|
"--exit-node=de-ber-wg-004.mullvad.ts.net"
|
|
|
|
];
|
2023-12-27 18:03:57 +01:00
|
|
|
};
|
2022-08-08 22:58:02 +02:00
|
|
|
|
2024-01-12 20:46:03 +01:00
|
|
|
systemd.services.tailscaled.serviceConfig.Environment =
|
|
|
|
[ "TS_DEBUG_FIREWALL_MODE=auto" ];
|
|
|
|
|
2024-01-06 03:06:53 +01:00
|
|
|
# call taiscale up without --auth-key
|
2024-01-25 02:18:09 +01:00
|
|
|
systemd.services.tailscaled-autoconnect = lib.mkIf (cfg.authKeyFile == null) {
|
|
|
|
after = [ "tailscaled.service" ];
|
|
|
|
wants = [ "tailscaled.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = ''
|
|
|
|
status=$(${config.systemd.package}/bin/systemctl show -P StatusText tailscaled.service)
|
|
|
|
if [[ $status != Connected* ]]; then
|
|
|
|
${cfg.package}/bin/tailscale up
|
|
|
|
fi
|
2024-01-21 21:40:27 +01:00
|
|
|
|
2024-01-25 02:18:09 +01:00
|
|
|
# some options cannot be set immediately
|
|
|
|
${cfg.package}/bin/tailscale up ${lib.escapeShellArgs cfg.extraUpFlags}
|
2024-01-21 21:41:21 +01:00
|
|
|
|
2024-01-25 02:18:09 +01:00
|
|
|
# TODO nginx.service currently fails because it supposedly doesn't have permissions for this file
|
|
|
|
${cfg.package}/bin/tailscale cert ${tailnetHost}
|
|
|
|
chown nginx:nginx /var/lib/tailscale/certs/${tailnetHost}.{key,crt}
|
|
|
|
'';
|
|
|
|
};
|
2024-01-21 21:41:21 +01:00
|
|
|
|
|
|
|
services.nginx.virtualHosts.${tailnetHost} = {
|
2024-01-25 02:15:35 +01:00
|
|
|
sslCertificate = "/var/lib/tailscale/certs/${tailnetHost}.crt";
|
|
|
|
sslCertificateKey = "/var/lib/tailscale/certs/${tailnetHost}.key";
|
2024-01-21 21:41:21 +01:00
|
|
|
};
|
2020-05-22 18:16:21 +02:00
|
|
|
}
|