@@ -85,13 +85,26 @@ in
8585 '';
8686 };
8787
88− certificatePrivateKeyBundle = lib.mkOption {
88+ sslCertificate = lib.mkOption {
8989 type = lib.types.nullOr lib.types.path;
9090 default = null;
9191 example = "/run/keys/ssl_cert";
9292 description = ''
93− The path to a PEM formatted bundle of the private key and
94− certificate to use for TLS connections.
93+ The path to a PEM formatted certificate to use for TLS/SSL
94+ connections.
95+
96+ This should be a string, not a Nix path, since Nix paths are
97+ copied into the world-readable Nix store.
98+ '';
99+ };
100+
101+ sslCertificateKey = lib.mkOption {
102+ type = lib.types.nullOr lib.types.path;
103+ default = null;
104+ example = "/run/keys/ssl_key";
105+ description = ''
106+ The path to a PEM formatted private key to use for TLS/SSL
107+ connections.
95108
96109 This should be a string, not a Nix path, since Nix paths are
97110 copied into the world-readable Nix store.
@@ -329,7 +342,7 @@ in
329342 });
330343 };
331344 })
332− (lib.optionalAttrs (cfg.certificatePrivateKeyBundle != null) {
345+ (lib.optionalAttrs (cfg.sslCertificate != null && cfg.sslCertificateKey != null) {
333346 "socket-binding-group=standard-sockets"."socket-binding=https".port = cfg.httpsPort;
334347 "core-service=management"."security-realm=UndertowRealm"."server-identity=ssl" = {
335348 keystore-path = "/run/keycloak/ssl/certificate_private_key_bundle.p12";
@@ -662,8 +675,9 @@ in
662675 umask u=rwx,g=,o=
663676
664677 install -T -m 0400 -o keycloak -g keycloak '${cfg.database.passwordFile}' /run/keycloak/secrets/db_password
665− '' + lib.optionalString (cfg.certificatePrivateKeyBundle != null) ''
666− install -T -m 0400 -o keycloak -g keycloak '${cfg.certificatePrivateKeyBundle}' /run/keycloak/secrets/ssl_cert_pk_bundle
678+ '' + lib.optionalString (cfg.sslCertificate != null && cfg.sslCertificateKey != null) ''
679+ install -T -m 0400 -o keycloak -g keycloak '${cfg.sslCertificate}' /run/keycloak/secrets/ssl_cert
680+ install -T -m 0400 -o keycloak -g keycloak '${cfg.sslCertificateKey}' /run/keycloak/secrets/ssl_key
667681 '';
668682 startPre = ''
669683 set -o errexit -o pipefail -o nounset -o errtrace
@@ -678,10 +692,13 @@ in
678692
679693 export JAVA_OPTS=-Djboss.server.config.user.dir=/run/keycloak/configuration
680694 add-user-keycloak.sh -u admin -p '${cfg.initialAdminPassword}'
681− '' + lib.optionalString (cfg.certificatePrivateKeyBundle != null) ''
695+ '' + lib.optionalString (cfg.sslCertificate != null && cfg.sslCertificateKey != null) ''
682696 pushd /run/keycloak/ssl/
683− cat /run/keycloak/secrets/ssl_cert_pk_bundle <(echo) /etc/ssl/certs/ca-certificates.crt > allcerts.pem
684− openssl pkcs12 -export -in /run/keycloak/secrets/ssl_cert_pk_bundle -chain \
697+ cat /run/keycloak/secrets/ssl_cert <(echo) \
698+ /run/keycloak/secrets/ssl_key <(echo) \
699+ /etc/ssl/certs/ca-certificates.crt \
700+ > allcerts.pem
701+ openssl pkcs12 -export -in /run/keycloak/secrets/ssl_cert -inkey /run/keycloak/secrets/ssl_key -chain \
685702 -name "${cfg.frontendUrl}" -out certificate_private_key_bundle.p12 \
686703 -CAfile allcerts.pem -passout pass:notsosecretpassword
687704 popd