1 import ./make-test-python.nix (
4 tls-cert = pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
6 -x509 -newkey rsa:4096 -sha256 -days 365 \
7 -nodes -out cert.pem -keyout key.pem \
8 -subj '/CN=headscale' -addext "subjectAltName=DNS:headscale"
11 cp key.pem cert.pem $out
16 meta.maintainers = with lib.maintainers; [ misterio77 ];
23 services.tailscale.enable = true;
24 security.pki.certificateFiles = [ "${tls-cert}/cert.pem" ];
37 server_url = "https://headscale";
38 ip_prefixes = [ "100.64.0.0/10" ];
42 stun_listen_addr = "0.0.0.0:${toString stunPort}";
44 dns.base_domain = "tailnet";
49 virtualHosts.headscale = {
51 sslCertificate = "${tls-cert}/cert.pem";
52 sslCertificateKey = "${tls-cert}/key.pem";
54 proxyPass = "http://127.0.0.1:${toString headscalePort}";
55 proxyWebsockets = true;
60 networking.firewall = {
65 allowedUDPPorts = [ stunPort ];
67 environment.systemPackages = [ pkgs.headscale ];
73 headscale.wait_for_unit("headscale")
74 headscale.wait_for_open_port(443)
76 # Create headscale user and preauth-key
77 headscale.succeed("headscale users create test")
78 authkey = headscale.succeed("headscale preauthkeys -u test create --reusable")
81 up_cmd = f"tailscale up --login-server 'https://headscale' --auth-key {authkey}"
85 # Check that they are reachable from the tailnet
86 peer1.wait_until_succeeds("tailscale ping peer2")
87 peer2.wait_until_succeeds("tailscale ping peer1.tailnet")