2022-09-09 17:26:49 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.tailscale;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.tailscale = {
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-09-09 17:40:42 +00:00
|
|
|
description = "The Tailscale domain. This is displayed at the top left of https://login.tailscale.com/admin, next to the Tailscale logo.";
|
2022-09-09 17:26:49 +00:00
|
|
|
};
|
|
|
|
|
2022-09-09 17:40:42 +00:00
|
|
|
enable = mkEnableOption "Tailscale client daemon";
|
2022-09-09 17:26:49 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.tailscale;
|
|
|
|
defaultText = literalExpression "pkgs.tailscale";
|
2022-09-09 17:40:42 +00:00
|
|
|
description = "The package to use for tailscale";
|
2022-09-09 17:26:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
magicDNS = {
|
2022-09-09 17:40:42 +00:00
|
|
|
enable = mkEnableOption "Whether to configure networking to work with Tailscale's MagicDNS.";
|
2022-09-09 17:26:49 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
2022-09-20 06:09:02 +00:00
|
|
|
|
|
|
|
launchd.daemons.tailscaled = {
|
2022-09-09 17:26:49 +00:00
|
|
|
# derived from
|
|
|
|
# https://github.com/tailscale/tailscale/blob/main/cmd/tailscaled/install_darwin.go#L30
|
|
|
|
serviceConfig = {
|
|
|
|
Label = "com.tailscale.tailscaled";
|
2022-09-20 06:09:02 +00:00
|
|
|
ProgramArguments = [
|
|
|
|
"/bin/sh" "-c"
|
|
|
|
"/bin/wait4path ${cfg.package} && ${cfg.package}/bin/tailscaled"
|
|
|
|
];
|
2022-09-09 17:26:49 +00:00
|
|
|
RunAtLoad = true;
|
|
|
|
};
|
|
|
|
};
|
2022-09-20 06:09:02 +00:00
|
|
|
|
2022-09-09 17:26:49 +00:00
|
|
|
networking = mkIf cfg.magicDNS.enable {
|
|
|
|
dns = [ "100.100.100.100" ];
|
|
|
|
search =
|
|
|
|
if cfg.domain == "" then
|
|
|
|
[ ]
|
|
|
|
else
|
|
|
|
[ "${cfg.domain}.beta.tailscale.net" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|