fix: need to split wildcard definitions because the nginx module would cause infinite recursion otherwise

This commit is contained in:
oddlama 2024-04-09 20:38:40 +02:00
parent c410a6b703
commit 76d6a094dc
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
8 changed files with 16 additions and 19 deletions

View file

@ -6,9 +6,8 @@
inherit
(lib)
assertMsg
attrNames
filter
filterAttrs
genAttrs
hasInfix
head
mkIf
@ -16,19 +15,14 @@
removeSuffix
types
;
wildcardDomains = attrNames (filterAttrs (_: v: v.wildcard) config.security.acme.certs);
in {
options.security.acme.certs = mkOption {
type = types.attrsOf (types.submodule (submod: {
options.wildcard = mkOption {
default = false;
type = types.bool;
description = "If set to true, this will automatically append `*.<domain>` to `extraDomainNames`.";
};
config.extraDomainNames = mkIf submod.config.wildcard ["*.${submod.config._module.args.name}"];
}));
options.security.acme.wildcardDomains = mkOption {
type = types.listOf types.str;
default = [];
description = ''
List of domains to which a wilcard certificate exists under the same name in `certs`.
All of these certs will automatically have `*.<domain>` appended to `extraDomainNames`.
'';
};
options.services.nginx.virtualHosts = mkOption {
@ -45,7 +39,7 @@ in {
matchingCerts =
filter
(x: !hasInfix "." (removeSuffix ".${x}" domain))
wildcardDomains;
config.security.acme.wildcardDomains;
in
mkIf submod.config.useACMEWildcardHost {
useACMEHost = assert assertMsg (matchingCerts != []) "No wildcard certificate was defined that matches ${domain}";
@ -53,4 +47,8 @@ in {
};
}));
};
config.security.acme.certs = genAttrs config.security.acme.wildcardDomains (domain: {
extraDomainNames = ["*.${domain}"];
});
}