-
-
Notifications
You must be signed in to change notification settings - Fork 13.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/tailscale-derper: init #306533
Merged
+137
−1
Merged
nixos/tailscale-derper: init #306533
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
|
||
let | ||
cfg = config.services.tailscale.derper; | ||
in | ||
{ | ||
meta.maintainers = with lib.maintainers; [ SuperSandro2000 ]; | ||
|
||
options = { | ||
services.tailscale.derper = { | ||
enable = lib.mkEnableOption "Tailscale Derper. See upstream doc <https://tailscale.com/kb/1118/custom-derp-servers> how to configure it on clients"; | ||
|
||
domain = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Domain name under which the derper server is reachable."; | ||
}; | ||
|
||
openFirewall = lib.mkOption { | ||
type = lib.types.bool; | ||
default = true; | ||
description = '' | ||
Whether to open the firewall for the specified port. | ||
Derper requires the used ports to be opened, otherwise it doesn't work as expected. | ||
''; | ||
}; | ||
|
||
package = lib.mkPackageOption pkgs [ | ||
"tailscale" | ||
"derper" | ||
] { }; | ||
|
||
stunPort = lib.mkOption { | ||
type = lib.types.port; | ||
default = 3478; | ||
description = '' | ||
STUN port to listen on. | ||
See online docs <https://tailscale.com/kb/1118/custom-derp-servers#prerequisites> on how to configure a different external port. | ||
''; | ||
}; | ||
|
||
port = lib.mkOption { | ||
type = lib.types.port; | ||
default = 8010; | ||
description = "The port the derper process will listen on. This is not the port tailscale will connect to."; | ||
}; | ||
|
||
verifyClients = lib.mkOption { | ||
type = lib.types.bool; | ||
default = false; | ||
description = '' | ||
Whether to verify clients against a locally running tailscale daemon if they are allowed to connect to this node or not. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
networking.firewall = lib.mkIf cfg.openFirewall { | ||
# port 80 and 443 are opened by nginx already | ||
allowedUDPPorts = [ cfg.stunPort ]; | ||
}; | ||
|
||
services = { | ||
nginx = { | ||
enable = true; | ||
upstreams.tailscale-derper = { | ||
servers."127.0.0.1:${toString cfg.port}" = { }; | ||
extraConfig = '' | ||
keepalive 64; | ||
''; | ||
}; | ||
virtualHosts."${cfg.domain}" = { | ||
addSSL = true; # this cannot be forceSSL as derper sends some information over port 80, too. | ||
locations."/" = { | ||
proxyPass = "http://tailscale-derper"; | ||
proxyWebsockets = true; | ||
extraConfig = '' | ||
keepalive_timeout 0; | ||
proxy_buffering off; | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
tailscale.enable = lib.mkIf cfg.verifyClients true; | ||
}; | ||
|
||
systemd.services.tailscale-derper = { | ||
serviceConfig = { | ||
ExecStart = | ||
"${lib.getExe' cfg.package "derper"} -a :${toString cfg.port} -c /var/lib/derper/derper.key -hostname=${cfg.domain} -stun-port ${toString cfg.stunPort}" | ||
+ lib.optionalString cfg.verifyClients " -verify-clients"; | ||
DynamicUser = true; | ||
Restart = "always"; | ||
RestartSec = "5sec"; # don't crash loop immediately | ||
StateDirectory = "derper"; | ||
Type = "simple"; | ||
|
||
CapabilityBoundingSet = [ "" ]; | ||
DeviceAllow = null; | ||
LockPersonality = true; | ||
NoNewPrivileges = true; | ||
MemoryDenyWriteExecute = true; | ||
PrivateDevices = true; | ||
PrivateUsers = true; | ||
ProcSubset = "pid"; | ||
ProtectClock = true; | ||
ProtectControlGroups = true; | ||
ProtectHostname = true; | ||
ProtectKernelLogs = true; | ||
ProtectKernelModules = true; | ||
ProtectKernelTunables = true; | ||
ProtectProc = "invisible"; | ||
RestrictAddressFamilies = [ | ||
"AF_INET" | ||
"AF_INET6" | ||
"AF_UNIX" | ||
]; | ||
RestrictNamespaces = true; | ||
RestrictRealtime = true; | ||
SystemCallArchitectures = "native"; | ||
SystemCallFilter = [ "@system-service" ]; | ||
}; | ||
wantedBy = [ "multi-user.target" ]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep things simple, I decided to keep the default port 80 and 443 tcp for now.