2023-07-16 00:09:54 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.shb.ssl;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.shb.ssl = {
|
|
|
|
enable = lib.mkEnableOption "selfhostblocks.ssl";
|
|
|
|
|
|
|
|
domain = lib.mkOption {
|
2023-11-30 07:20:21 +01:00
|
|
|
description = "Domain to ask a wildcard certificate for.";
|
2023-07-16 00:09:54 +02:00
|
|
|
type = lib.types.str;
|
|
|
|
example = "domain.com";
|
|
|
|
};
|
|
|
|
|
2023-09-15 07:21:15 +02:00
|
|
|
dnsProvider = lib.mkOption {
|
2023-11-30 07:20:21 +01:00
|
|
|
description = "DNS provider to use. See https://go-acme.github.io/lego/dns/ for the list of supported providers.";
|
2023-09-15 07:21:15 +02:00
|
|
|
type = lib.types.str;
|
|
|
|
example = "linode";
|
|
|
|
};
|
|
|
|
|
2023-11-30 07:20:21 +01:00
|
|
|
credentialsFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = ''Credentials file location for the chosen DNS provider.
|
|
|
|
|
|
|
|
The content of this file must expose environment variables as written in the
|
|
|
|
[documentation](https://go-acme.github.io/lego/dns/) of each DNS provider.
|
|
|
|
|
|
|
|
For example, if the documentation says the credential must be located in the environment
|
|
|
|
variable DNSPROVIDER_TOKEN, then the file content must be:
|
|
|
|
|
|
|
|
DNSPROVIDER_TOKEN=xyz
|
|
|
|
|
|
|
|
You can put non-secret environment variables here too or use shb.ssl.additionalcfg instead.
|
|
|
|
'';
|
|
|
|
example = "/run/secrets/ssl";
|
|
|
|
};
|
|
|
|
|
|
|
|
additionalCfg = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
|
|
|
description = lib.mdDoc ''Additional environment variables used to configure the DNS provider.
|
|
|
|
|
|
|
|
For secrets, use shb.ssl.credentialsFile instead.
|
|
|
|
|
|
|
|
See the chose provider's [documentation](https://go-acme.github.io/lego/dns/) for available
|
|
|
|
options.
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''{
|
|
|
|
DNSPROVIDER_TIMEOUT = "10";
|
|
|
|
DNSPROVIDER_PROPAGATION_TIMEOUT = "240";
|
|
|
|
}'';
|
|
|
|
};
|
|
|
|
|
2023-09-15 07:21:15 +02:00
|
|
|
dnsResolver = lib.mkOption {
|
2023-11-30 07:20:21 +01:00
|
|
|
description = "IP of a DNS server used to resolve hostnames.";
|
2023-09-15 07:21:15 +02:00
|
|
|
type = lib.types.str;
|
|
|
|
default = "8.8.8.8";
|
|
|
|
};
|
|
|
|
|
2023-07-16 00:09:54 +02:00
|
|
|
adminEmail = lib.mkOption {
|
2023-11-30 07:20:21 +01:00
|
|
|
description = "Admin email in case certificate retrieval goes wrong.";
|
2023-07-16 00:09:54 +02:00
|
|
|
type = lib.types.str;
|
|
|
|
};
|
2023-11-30 07:20:21 +01:00
|
|
|
|
|
|
|
debug = lib.mkOption {
|
|
|
|
description = "Enable debug logging";
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2023-07-16 00:09:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
users.users.${config.services.nginx.user} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "nginx";
|
|
|
|
extraGroups = [ config.security.acme.defaults.group ];
|
|
|
|
};
|
2023-11-17 05:43:44 +01:00
|
|
|
users.groups.nginx = {};
|
2023-07-16 00:09:54 +02:00
|
|
|
|
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
certs."${cfg.domain}" = {
|
|
|
|
extraDomainNames = ["*.${cfg.domain}"];
|
|
|
|
};
|
|
|
|
defaults = {
|
|
|
|
email = cfg.adminEmail;
|
2023-09-15 07:21:15 +02:00
|
|
|
inherit (cfg) dnsProvider dnsResolver;
|
2023-11-30 07:20:21 +01:00
|
|
|
credentialsFile = cfg.credentialsFile;
|
|
|
|
enableDebugLogs = cfg.debug;
|
2023-07-16 00:09:54 +02:00
|
|
|
};
|
|
|
|
};
|
2023-11-30 07:20:21 +01:00
|
|
|
|
|
|
|
systemd.services."acme-${cfg.domain}".environment = cfg.additionalCfg;
|
2023-07-16 00:09:54 +02:00
|
|
|
};
|
|
|
|
}
|