33 lines
1.1 KiB
Nix
33 lines
1.1 KiB
Nix
{
|
|
den.quirks.tunnel.description = "cloudflared ingress: { subdomain, port, scheme ? \"http\" }";
|
|
|
|
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 = "${t.scheme or "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;
|
|
};
|
|
};
|
|
};
|
|
}
|