2023-07-16 17:53:02 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-08-03 17:32:02 +00:00
|
|
|
namespace,
|
2023-07-16 17:53:02 +00:00
|
|
|
...
|
2024-08-03 17:32:02 +00:00
|
|
|
}: let
|
|
|
|
inherit (lib) mkOption mkEnableOption mkIf types;
|
|
|
|
|
2023-07-16 17:53:02 +00:00
|
|
|
cfg = config.aa.security.acme;
|
|
|
|
in {
|
2024-08-03 17:32:02 +00:00
|
|
|
options.aa.security.acme = {
|
2023-07-16 17:53:02 +00:00
|
|
|
enable = mkEnableOption "Automatic Certificate Management Environment (ACME)";
|
|
|
|
useStaging = mkOption {
|
2024-08-03 17:32:02 +00:00
|
|
|
type = types.bool;
|
2023-07-16 17:53:02 +00:00
|
|
|
description = ''
|
|
|
|
Use the staging environment (use when configuring for the first time to
|
|
|
|
avoid being locked out).
|
|
|
|
'';
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
domainName = mkOption {
|
2024-08-03 17:32:02 +00:00
|
|
|
type = types.str;
|
2023-07-16 17:53:02 +00:00
|
|
|
description = "The domain to request a wildcard cert for.";
|
|
|
|
};
|
2024-05-04 02:57:00 +00:00
|
|
|
isWildcard = mkOption {
|
2024-08-03 17:32:02 +00:00
|
|
|
type = types.bool;
|
2024-05-04 02:57:00 +00:00
|
|
|
default = true;
|
|
|
|
description = "Whether or not to request a wildcard cert.";
|
|
|
|
};
|
2023-07-16 17:53:02 +00:00
|
|
|
dnsCredentialsFile = mkOption {
|
2024-08-03 17:32:02 +00:00
|
|
|
type = types.path;
|
2023-07-16 17:53:02 +00:00
|
|
|
description = "The path to the credentials file for the DNS provider.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Only supports exactly one wildcard cert using Cloudflare (only use case I have)
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
defaults = {
|
|
|
|
email = config.aa.user.email;
|
|
|
|
group = "nginx";
|
|
|
|
server = mkIf cfg.useStaging "https://acme-staging-v02.api.letsencrypt.org/directory";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Wildcard cert
|
|
|
|
certs."${cfg.domainName}" = {
|
|
|
|
group = "nginx";
|
|
|
|
dnsProvider = "cloudflare";
|
|
|
|
# Private network resolves *.kilonull.com to private servers but `lego`
|
|
|
|
# (acme client under the hood) needs to find the cloudflare nameservers
|
|
|
|
# to determine the correct zone to apply changes in. Use cloudflare's
|
|
|
|
# own DNS to make `lego` happy (will resolve names to a public IP).
|
|
|
|
dnsResolver = "1.1.1.1:53";
|
|
|
|
credentialsFile = cfg.dnsCredentialsFile;
|
2024-05-04 02:57:00 +00:00
|
|
|
extraDomainNames = mkIf cfg.isWildcard [("*." + cfg.domainName)];
|
2023-07-16 17:53:02 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|