aboutsummaryrefslogtreecommitdiff
path: root/modules/services/nixos/selfhost/headscale.nix
diff options
context:
space:
mode:
authorCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-01-18 08:10:20 -0600
committerCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-01-18 08:10:20 -0600
commitd6c4bd6d87d31a2c688fb2fcfdb0cb15d8f9163d (patch)
tree07f85b8fac540f7625f90b10ee500a1bc8116ac3 /modules/services/nixos/selfhost/headscale.nix
parented2550a41c8429a1d2fe897deb878717c2ebc3d1 (diff)
parent43af7f28b28021932b318964a953463d8dd79372 (diff)
Merge branch 'main' into wg
Diffstat (limited to 'modules/services/nixos/selfhost/headscale.nix')
-rw-r--r--modules/services/nixos/selfhost/headscale.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/modules/services/nixos/selfhost/headscale.nix b/modules/services/nixos/selfhost/headscale.nix
new file mode 100644
index 0000000..2bdcca1
--- /dev/null
+++ b/modules/services/nixos/selfhost/headscale.nix
@@ -0,0 +1,75 @@
+{
+ config,
+ pkgs,
+ lib,
+ ...
+}: let
+ cfg = config.collinux.services.selfhost.headscale;
+
+ acl_file = (pkgs.formats.json {}).generate "acl.json" {
+ ssh = [
+ {
+ src = ["collin@"];
+ dst = ["collin@"];
+ users = ["autogroup:nonroot" "root"];
+ action = "accept";
+ }
+ ];
+ };
+in
+ lib.mkIf cfg.enable {
+ services.headscale = {
+ enable = true;
+ address = cfg.bind_host;
+ port = cfg.port;
+ settings = {
+ server_url = "https://${cfg.root_url}";
+
+ database.type = "sqlite";
+
+ dns = {
+ magic_dns = true;
+ base_domain = "collinux.tailnet";
+ override_local_dns = true;
+ nameservers.global = ["9.9.9.9" "149.112.112.112" "2620:fe::fe" "2620:fe::9"];
+ };
+
+ policy.path = "${acl_file}";
+
+ prefixes = {
+ "v4" = "100.100.0.0/16";
+ allocation = "random";
+ };
+
+ # leave tls for caddy to worry about
+ tls_cert_path = null;
+ tls_key_path = null;
+
+ logtail.enabled = false;
+ };
+ };
+
+ # make sure headscale can start before tailscale
+ systemd.services."headscale" = lib.mkIf config.collinux.services.networking.tailscale.enable {
+ after = lib.mkForce ["network.target"];
+ before = lib.mkForce ["headscale.target"];
+ wants = lib.mkForce ["network.target" "headscale.target"];
+ };
+
+ systemd.targets."headscale" = {
+ description = "Target represents headscale is running. started by headscale.service";
+ };
+
+ environment.systemPackages = [pkgs.headscale];
+
+ services.caddy = lib.mkIf cfg.caddy.enable {
+ virtualHosts.${cfg.root_url}.extraConfig = ''
+ ${
+ if cfg.caddy.bind_tailscale
+ then "bind tailscale/${cfg.service_name}"
+ else ""
+ }
+ reverse_proxy ${cfg.bind_host}:${toString cfg.port}
+ '';
+ };
+ }