···
# Attrset with the ACME certificate names split by whether or not they depend
# on H2O serving challenges.
···
+
certNames = lib.lists.foldl partition {
} acmeEnabledHostsConfigs;
+
all = certNames.dependent ++ certNames.independent;
···
names = getNames name value;
+
acmeSettings = lib.optionalAttrs (builtins.elem names.cert acmeCertNames.dependent) (
acmeChallengePath = "/.well-known/acme-challenge";
···
hasTLSRecommendations = tlsRecommendations != null && mozTLSRecs != null;
+
# ATTENTION: Let’s Encrypt has sunset OCSP stapling.
+
# If using ACME, this module will disable H2O’s default OCSP
+
# See: https://letsencrypt.org/2024/12/05/ending-ocsp/
+
lib.optionalAttrs (builtins.elem names.cert acmeCertNames.all) {
+
ocsp-update-interval = 0;
+
# Mozilla’s ssl-config-generator is at present still
+
# recommending this setting as well, but this module will
+
# skip setting a stapling value as Let’s Encrypt + ACME is
+
# the most likely use case.
+
# See: https://github.com/mozilla/ssl-config-generator/issues/323
+
// lib.optionalAttrs hasTLSRecommendations (
+
recs = mozTLSRecs.${tlsRecommendations};
+
min-version = builtins.head recs.tls_versions;
+
cipher-preference = "server";
+
"cipher-suite-tls1.3" = recs.ciphersuites;
+
// lib.optionalAttrs (recs.ciphers.openssl != [ ]) {
+
cipher-suite = lib.concatStringsSep ":" recs.ciphers.openssl;
···
+
++ lib.optional (builtins.elem names.cert acmeCertNames.all) {
key-file = "${certs.${names.cert}.directory}/key.pem";
certificate-file = "${certs.${names.cert}.directory}/fullchain.pem";
···
groups = config.users.groups;
config.systemd.services.h2o
+
] ++ lib.optional (acmeCertNames.all != [ ]) config.systemd.services.h2o-config-reload;
···
description = "H2O HTTP server";
wantedBy = [ "multi-user.target" ];
+
wants = lib.concatLists (map (certName: [ "acme-finished-${certName}.target" ]) acmeCertNames.all);
# Since H2O will be hosting the challenges, H2O must be started
+
before = builtins.map (certName: "acme-${certName}.service") acmeCertNames.dependent;
+
++ builtins.map (certName: "acme-selfsigned-${certName}.service") acmeCertNames.all
+
++ builtins.map (certName: "acme-${certName}.service") acmeCertNames.independent; # avoid loading self-signed key w/ real cert, or vice-versa
ExecStart = "${h2oExe} --mode 'master'";
···
systemd.services.h2o-config-reload =
+
tlsTargets = map (certName: "acme-${certName}.target") acmeCertNames.all;
+
tlsServices = map (certName: "acme-${certName}.service") acmeCertNames.all;
+
mkIf (acmeCertNames.all != [ ]) {
wantedBy = tlsServices ++ [ "multi-user.target" ];
+
ConditionPathExists = map (
+
certName: "${certs.${certName}.directory}/fullchain.pem"
# Disable rate limiting for this since it may be triggered quickly
# a bunch of times if a lot of certificates are renewed in quick
# succession. The reload itself is cheap, so even doing a lot of them