From 309bf1db8096585751bbf55eba6b3b639699c095 Mon Sep 17 00:00:00 2001 From: Felix Singer Date: Wed, 24 Sep 2025 06:44:38 +0200 Subject: [PATCH] nixos/murmur: Allow hooking up to ACME certificate service In order to simplify using certificates provided by ACME, add the option `services.murmur.tls.useACMEHost`. If set, the options keyPath, certPath and caPath are pre-configured appropriately. Also, add the appriopriate ACME systemd service to Murmur's dependencies if useACMEHost is set. Signed-off-by: Felix Singer --- nixos/modules/services/networking/murmur.nix | 35 +++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/networking/murmur.nix b/nixos/modules/services/networking/murmur.nix index f9f3f87e4163..8f72e3c52b84 100644 --- a/nixos/modules/services/networking/murmur.nix +++ b/nixos/modules/services/networking/murmur.nix @@ -7,6 +7,8 @@ let cfg = config.services.murmur; + acmeHostDir = config.security.acme.certs."${cfg.tls.useACMEHost}".directory; + forking = cfg.logToFile; configFile = pkgs.writeText "murmurd.ini" '' database=${cfg.stateDir}/murmur.sqlite @@ -246,21 +248,38 @@ in tls = { certPath = lib.mkOption { type = lib.types.nullOr lib.types.path; - default = null; + default = if (cfg.tls.useACMEHost != null) then "${acmeHostDir}/cert.pem" else null; + defaultText = lib.literalMD "If {option}`services.murmur.tls.useACMEHost` is set, defaults to what's provided by the ACME module."; description = "Path to your TLS certificate."; }; keyPath = lib.mkOption { type = lib.types.nullOr lib.types.path; - default = null; + default = if (cfg.tls.useACMEHost != null) then "${acmeHostDir}/key.pem" else null; + defaultText = lib.literalMD "If {option}`services.murmur.tls.useACMEHost` is set, defaults to what's provided by the ACME module."; description = "Path to your TLS key."; }; caPath = lib.mkOption { type = lib.types.nullOr lib.types.path; - default = null; + default = if (cfg.tls.useACMEHost != null) then "${acmeHostDir}/chain.pem" else null; + defaultText = lib.literalMD "If {option}`services.murmur.tls.useACMEHost` is set, defaults to what's provided by the ACME module."; description = "Path to your TLS CA certificate."; }; + + useACMEHost = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + example = "mumble.example.com"; + description = '' + Host of an existing Let's Encrypt certificate to use for TLS. + Make sure that the certificate directory is readable by the + `murmur` user or group. *Note that this option does not + create any certificates and it doesn't add subdomains to + existing ones – you will need to create them manually using + {option}`security.acme.certs`.* + ''; + }; }; extraConfig = lib.mkOption { @@ -324,10 +343,18 @@ in allowedUDPPorts = [ cfg.port ]; }; + security.acme.certs = lib.mkIf (cfg.tls.useACMEHost != null) { + "${cfg.tls.useACMEHost}".reloadServices = [ "murmur.service" ]; + }; + systemd.services.murmur = { description = "Murmur Chat Service"; wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; + after = [ + "network.target" + ] + ++ lib.optional (cfg.tls.useACMEHost != null) "acme-${cfg.tls.useACMEHost}.service"; + wants = lib.mkIf (cfg.tls.useACMEHost != null) [ "acme-${cfg.tls.useACMEHost}.service" ]; preStart = '' ${pkgs.envsubst}/bin/envsubst \ -o /run/murmur/murmurd.ini \