Files
nix/modules/services/cloudflared.nix
T

34 lines
1.1 KiB
Nix

{
den.quirks.tunnel.description = "cloudflared ingress: { subdomain, port }";
# per host: den.hosts.<sys>.<host>.cloudflared = { uuid = "..."; protocol = "http2"; # optional };
den.aspects.services.cloudflared = {
nixos = { tunnel, host, pkgs, lib, config, ... }: let
inherit (host.cloudflared) uuid;
inherit (host) domain;
user = host.owner;
in {
environment.systemPackages = [ pkgs.cloudflared ];
environment.etc."cloudflared/${uuid}.json".source = "${config.users.users.${user}.home}/.cloudflared/${uuid}.json";
services.cloudflared = {
enable = true;
tunnels.${uuid} = {
credentialsFile = "/etc/cloudflared/${uuid}.json";
default = "http_status:404";
ingress = lib.listToAttrs (map (t: {
name = "${t.subdomain}.${domain}";
value = "http://127.0.0.1:${toString t.port}";
}) tunnel);
};
};
systemd.services."cloudflared-tunnel-${uuid}".environment = lib.mkIf (host.cloudflared ? protocol) {
TUNNEL_TRANSPORT_PROTOCOL = lib.mkForce host.cloudflared.protocol;
};
};
};
}