tunnel config

This commit is contained in:
Satria 2026-03-06 19:35:05 +07:00
commit fc66316343

View file

@ -1,16 +1,36 @@
{ homelab, ... }: { { pkgs, lib, homelab, ... }: let
routes = {
"git.${homelab.domain}" = "http://localhost:3000";
"auth.${homelab.domain}" = "http://localhost:1411";
"dash.${homelab.domain}" = "http://localhost:5070";
"gallery.${homelab.domain}" = "http://localhost:2284";
};
in {
services.cloudflared = { services.cloudflared = {
enable = true; enable = true;
tunnels.homelab = { tunnels.homelab = {
credentialsFile = "/mnt/data/cloudflared/homelab.json"; credentialsFile = "/mnt/data/cloudflared/homelab.json";
certificateFile = "/mnt/data/cloudflared/cert.pem"; certificateFile = "/mnt/data/cloudflared/cert.pem";
default = "http_status:404"; default = "http_status:404";
ingress = { ingress = routes;
"git.${homelab.domain}" = "http://localhost:3000";
"auth.${homelab.domain}" = "http://localhost:1411";
"dash.${homelab.domain}" = "http://localhost:5070";
"gallery.${homelab.domain}" = "http://localhost:2284";
}; };
systemd.services.cloudflared-dns-route = {
description = "Sync Cloudflare Tunnel DNS routes";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
RemainAfterExit = true;
Type = "oneshot";
User = "root";
};
script = lib.concatMapStringsSep "\n" (domain: ''
echo "Ensuring DNS route for ${domain}..."
${pkgs.cloudflared}/bin/cloudflared tunnel --origincert /mnt/data/cloudflared/cert.pem route dns ${homelab.cf-tunnel-id} ${domain} || true
'') builtins.attrNames routes;
}; };
}; };
} }