{ config, lib, ... }: with lib; let cfg = config.local; in { options.local = with types; { domains = mkOption { type = attrsOf (attrsOf str); }; certs = mapAttrs (_: _: { enable = mkEnableOption "TLS cert for ${name}"; }) cfg.domains; }; config = { security.acme = { acceptTerms = true; defaults = { email = "security@${config.networking.domain}"; renewInterval = "weekly"; }; certs = let domainSort = sort (a: b: splitString "." a < splitString "." b); certConfig = domains: { domain = domains.main; extraDomainNames = domainSort (attrValues (filterAttrs (k: _: k != "main") domains)); webroot = "/var/lib/acme/acme-challenge"; }; in mapAttrs' (_: value: nameValuePair value.main (certConfig value)) (filterAttrs (name: _: cfg.certs.${name}.enable) cfg.domains); }; local.domains = import ./domains.nix; }; }