-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtailscale.nix
53 lines (49 loc) · 1.17 KB
/
tailscale.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
config,
lib,
...
}: let
keyNames = [
"ssh_host_rsa_key"
"ssh_host_ed25519_key"
"ssh_host_ecdsa_key"
];
prefix = "/var/lib/tailscale/ssh";
in {
services.tailscale = {
enable = true;
extraUpFlags = ["--ssh"];
};
networking.firewall.interfaces.${config.services.tailscale.interfaceName} = {
allowedTCPPorts = [
22
];
allowedUDPPorts = [
25565 # minecraft query port
];
};
networking.firewall.checkReversePath = "loose";
services.openssh = {
openFirewall = false;
extraConfig = lib.mkOrder 0 ''
${lib.concatMapStringsSep "\n" (k: "HostKey ${prefix}/${k}") keyNames}
'';
hostKeys = lib.mkForce [];
};
systemd.paths = lib.mapAttrs' (name: value: lib.nameValuePair "tailscale-${name}" value) (lib.genAttrs keyNames (key: {
wantedBy = ["paths.target"];
pathConfig = {
Unit = "sshd-restart-tailscale.service";
PathModified = "${prefix}/${key}";
};
}));
systemd.services."sshd-restart-tailscale" = {
serviceConfig.Type = "oneshot";
script = ''
systemctl try-restart sshd.service
'';
};
systemd.services."sshd" = {
after = ["tailscaled.service"];
};
}