@@ -15,6 +15,9 @@ let
1515 } // (optionalAttrs vhostConfig.enableACME {
1616 sslCertificate = "/var/lib/acme/${serverName}/fullchain.pem";
1717 sslCertificateKey = "/var/lib/acme/${serverName}/key.pem";
18+ }) // (optionalAttrs (vhostConfig.useACMEHost != null) {
19+ sslCertificate = "/var/lib/acme/${vhostConfig.useACMEHost}/fullchain.pem";
20+ sslCertificateKey = "/var/lib/acme/${vhostConfig.useACMEHost}/key.pem";
1821 })
1922 ) cfg.virtualHosts;
2023 enableIPv6 = config.networking.enableIPv6;
@@ -174,7 +177,7 @@ let
174177
175178 redirectListen = filter (x: !x.ssl) defaultListen;
176179
177− acmeLocation = ''
180+ acmeLocation = optionalString (vhost.enableACME || vhost.useACMEHost != null) ''
178181 location /.well-known/acme-challenge {
179182 ${optionalString (vhost.acmeFallbackHost != null) "try_files $uri @acme-fallback;"}
180183 root ${vhost.acmeRoot};
@@ -194,7 +197,7 @@ let
194197 ${concatMapStringsSep "\n" listenString redirectListen}
195198
196199 server_name ${vhost.serverName} ${concatStringsSep " " vhost.serverAliases};
197− ${optionalString vhost.enableACME acmeLocation}
200+ ${acmeLocation}
198201 location / {
199202 return 301 https://$host$request_uri;
200203 }
@@ -204,7 +207,7 @@ let
204207 server {
205208 ${concatMapStringsSep "\n" listenString hostListen}
206209 server_name ${vhost.serverName} ${concatStringsSep " " vhost.serverAliases};
207− ${optionalString vhost.enableACME acmeLocation}
210+ ${acmeLocation}
208211 ${optionalString (vhost.root != null) "root ${vhost.root};"}
209212 ${optionalString (vhost.globalRedirect != null) ''
210213 return 301 http${optionalString hasSSL "s"}://${vhost.globalRedirect}$request_uri;
@@ -555,6 +558,14 @@ in
555558 are mutually exclusive.
556559 '';
557560 }
561+
562+ {
563+ assertion = all (conf: !(conf.enableACME && conf.useACMEHost != null)) (attrValues virtualHosts);
564+ message = ''
565+ Options services.nginx.service.virtualHosts.<name>.enableACME and
566+ services.nginx.virtualHosts.<name>.useACMEHost are mutually exclusive.
567+ '';
568+ }
558569 ];
559570
560571 systemd.services.nginx = {
@@ -580,7 +591,7 @@ in
580591 security.acme.certs = filterAttrs (n: v: v != {}) (
581592 let
582593 vhostsConfigs = mapAttrsToList (vhostName: vhostConfig: vhostConfig) virtualHosts;
583− acmeEnabledVhosts = filter (vhostConfig: vhostConfig.enableACME) vhostsConfigs;
594+ acmeEnabledVhosts = filter (vhostConfig: vhostConfig.enableACME && vhostConfig.useACMEHost == null) vhostsConfigs;
584595 acmePairs = map (vhostConfig: { name = vhostConfig.serverName; value = {
585596 user = cfg.user;
586597 group = lib.mkDefault cfg.group;