nixos-config/profiles/servers/headscale.nix

64 lines
2.0 KiB
Nix
Raw Normal View History

{ headscale-list ? [] }: { config, lib, inputs, pkgs, ... }:
let
domain = "wg.ataraxiadev.com";
in {
environment.systemPackages = [ config.services.headscale.package ];
services.headscale = {
enable = true;
address = "0.0.0.0";
port = 8005;
settings = {
server_url = "https://${domain}";
ip_prefixes = [
"fd7a:115c:a1e0::/64" "100.64.0.0/16"
];
2024-12-28 11:33:12 +03:00
dns = {
2024-01-25 20:59:39 +03:00
override_local_dns = true;
2024-12-28 11:33:12 +03:00
base_domain = "tailnet.ataraxiadev.com";
nameservers.global = [ "127.0.0.1" ];
2024-01-21 17:40:07 +03:00
extra_records = headscale-list;
};
oidc = {
only_start_if_oidc_is_available = true;
issuer = "https://auth.ataraxiadev.com/application/o/headscale/";
client_id = "n6UBhK8PahexLPb7GkU1xzoFLcYxQX0HWDytpUoi";
2024-01-25 20:59:39 +03:00
client_secret_path = config.sops.secrets.headscale-oidc.path;
scope = [ "openid" "profile" "email" "groups" ];
allowed_groups = [ "headscale" ];
strip_email_domain = true;
};
2024-01-25 20:59:39 +03:00
grpc_listen_addr = "127.0.0.1:50443";
grpc_allow_insecure = true;
disable_check_updates = true;
ephemeral_node_inactivity_timeout = "4h";
};
};
2024-01-22 16:44:51 +03:00
sops.secrets.headscale-oidc = {
sopsFile = inputs.self.secretsDir + /home-hypervisor/headscale.yaml;
owner = "headscale";
2024-01-22 16:44:51 +03:00
restartUnits = [ "headscale.service" ];
};
2024-02-01 22:50:44 +03:00
systemd.services.headscale = {
serviceConfig.TimeoutStopSec = 15;
serviceConfig.ExecStartPre = let
waitAuthnetikReady = pkgs.writeShellScript "waitAuthnetikReady" ''
# Check until authentik is alive
max_retry=100
counter=0
until ${lib.getExe pkgs.curl} -fsSL http://auth.ataraxiadev.com/-/health/ready/
do
echo "Waiting for the authentik..."
sleep 3
[[ counter -eq $max_retry ]] && echo "Could not connect to authentik!" && exit 1
echo "Trying again. Try #$counter"
((counter++))
done
echo "Authentik is alive!"
'';
in waitAuthnetikReady;
2024-02-01 22:50:44 +03:00
};
persist.state.directories = [ "/var/lib/headscale" ];
}