caddy: wildcard TLS via DNS-01 challenge + ddns-updater for Njalla
Build Caddy with the caddy-dns/njalla plugin to enable DNS-01 ACME challenges. This issues a single wildcard certificate for *.sigkill.computer instead of per-subdomain certificates, reducing Let's Encrypt API calls and certificate management overhead. Add ddns-updater service (nixpkgs services.ddns-updater) configured with Njalla provider to automatically update DNS records when the server's public IP changes.
This commit is contained in:
@@ -71,6 +71,8 @@
|
|||||||
./services/mollysocket.nix
|
./services/mollysocket.nix
|
||||||
|
|
||||||
./services/harmonia.nix
|
./services/harmonia.nix
|
||||||
|
|
||||||
|
./services/ddns-updater.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
# Hosts entries for CI/CD deploy targets
|
# Hosts entries for CI/CD deploy targets
|
||||||
|
|||||||
@@ -46,6 +46,20 @@
|
|||||||
group = "caddy";
|
group = "caddy";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Njalla API token (NJALLA_API_TOKEN=...) for Caddy DNS-01 challenge
|
||||||
|
njalla-api-token-env = {
|
||||||
|
file = ../secrets/njalla-api-token-env.age;
|
||||||
|
mode = "0400";
|
||||||
|
owner = "caddy";
|
||||||
|
group = "caddy";
|
||||||
|
};
|
||||||
|
|
||||||
|
# ddns-updater config.json with Njalla provider credentials
|
||||||
|
ddns-updater-config = {
|
||||||
|
file = ../secrets/ddns-updater-config.age;
|
||||||
|
mode = "0400";
|
||||||
|
};
|
||||||
|
|
||||||
jellyfin-api-key = {
|
jellyfin-api-key = {
|
||||||
file = ../secrets/jellyfin-api-key.age;
|
file = ../secrets/jellyfin-api-key.age;
|
||||||
mode = "0400";
|
mode = "0400";
|
||||||
|
|||||||
BIN
secrets/ddns-updater-config.age
Normal file
BIN
secrets/ddns-updater-config.age
Normal file
Binary file not shown.
BIN
secrets/njalla-api-token-env.age
Normal file
BIN
secrets/njalla-api-token-env.age
Normal file
Binary file not shown.
@@ -56,9 +56,19 @@ in
|
|||||||
enable = true;
|
enable = true;
|
||||||
email = "titaniumtown@proton.me";
|
email = "titaniumtown@proton.me";
|
||||||
|
|
||||||
# Enable on-demand TLS for old domain redirects
|
# Build with Njalla DNS provider for DNS-01 ACME challenges (wildcard certs)
|
||||||
# Certs are issued dynamically when subdomains are accessed
|
package = pkgs.caddy.withPlugins {
|
||||||
|
plugins = [ "github.com/caddy-dns/njalla@v0.0.0-20250823094507-f709141f1fe6" ];
|
||||||
|
hash = "sha256-rrOAR6noTDpV/I/hZXxhz0OXVJKu0mFQRq87RUrpmzw=";
|
||||||
|
};
|
||||||
|
|
||||||
globalConfig = ''
|
globalConfig = ''
|
||||||
|
# Wildcard cert for *.${newDomain} via DNS-01 challenge
|
||||||
|
acme_dns njalla {
|
||||||
|
api_token {env.NJALLA_API_TOKEN}
|
||||||
|
}
|
||||||
|
|
||||||
|
# On-demand TLS for old domain redirects
|
||||||
on_demand_tls {
|
on_demand_tls {
|
||||||
ask http://localhost:9123/check
|
ask http://localhost:9123/check
|
||||||
}
|
}
|
||||||
@@ -106,6 +116,9 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Inject Njalla API token for DNS-01 challenge
|
||||||
|
systemd.services.caddy.serviceConfig.EnvironmentFile = config.age.secrets.njalla-api-token-env.path;
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d ${config.services.caddy.dataDir} 700 ${config.services.caddy.user} ${config.services.caddy.group}"
|
"d ${config.services.caddy.dataDir} 700 ${config.services.caddy.user} ${config.services.caddy.group}"
|
||||||
];
|
];
|
||||||
|
|||||||
14
services/ddns-updater.nix
Normal file
14
services/ddns-updater.nix
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
services.ddns-updater = {
|
||||||
|
enable = true;
|
||||||
|
environment = {
|
||||||
|
PERIOD = "5m";
|
||||||
|
# ddns-updater reads config from this path at runtime
|
||||||
|
CONFIG_FILEPATH = config.age.secrets.ddns-updater-config.path;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user