This is an automated email from the git hooks/post-receive script.

dannym pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new 44d178265c services: Add mosquitto-service-type.
44d178265c is described below

commit 44d178265c23834a6050de06863cd0fcde64e4f8
Author: Evgeny Pisemsky <m...@pisemsky.site>
AuthorDate: Fri May 9 19:46:49 2025 +0200

    services: Add mosquitto-service-type.
    
    * gnu/services/messaging.scm (<mosquitto-configuration>): New record type.
    (mosquitto-accounts): New procedure.
    (mosquitto-shepherd-service): New procedure.
    (mosquitto-service-type): New variable.
    * doc/guix.texi (Messaging Services): Document it.
    
    Change-Id: I3500c5b6b69084c1f4a6da66ea45bfd42c871f3f
    Signed-off-by: Danny Milosavljevic <dan...@friendly-machines.com>
---
 doc/guix.texi              | 94 ++++++++++++++++++++++++++++++++++++++++++++++
 gnu/services/messaging.scm | 72 ++++++++++++++++++++++++++++++++++-
 2 files changed, 165 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 889eab2ab3..cbc4dd0fc9 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -139,6 +139,7 @@ Copyright @copyright{} 2025 Sören Tempel@*
 Copyright @copyright{} 2025 Rostislav Svoboda@*
 Copyright @copyright{} 2025 Zacchaeus@*
 Copyright @copyright{} 2025 Sergio Pastor Pérez@*
+Copyright @copyright{} 2024 Evgeny Pisemsky@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -31303,6 +31304,99 @@ Extra options will be passed to @command{snuik}, 
please run
 @end table
 @end deftp
 
+@subsubheading Mosquitto Service
+
+@url{https://mosquitto.org/,Mosquitto} is a lightweight message broker
+that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1.  It is
+suitable for use on all devices from low power single board computers to
+full servers.
+
+@defvar mosquitto-service-type
+This is the service type for the @url{https://mosquitto.org/,Mosquitto}
+MQTT broker.  Its value is a @code{mosquitto-configuration} (see below).
+@end defvar
+
+@deftp {Data Type} mosquitto-configuration
+This is the configuration for Mosquitto, with the following fields:
+
+@table @asis
+@item @code{package} (default: @code{mosquitto})
+The Mosquitto package to use.
+
+@item @code{config-file} (default: @code{#f})
+The Mosquitto configuration file as a file-like object or the value
+@code{#f} to use the default configuration.
+
+@item @code{user} (default: @code{"mosquitto"})
+Owner of the broker process.
+
+@item @code{group} (default: @code{"mosquitto"})
+Owner's group of the broker process.
+@end table
+@end deftp
+
+@subsubheading Mosquitto Service
+
+@url{https://mosquitto.org/,Mosquitto} is a lightweight message broker
+that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1.  It is
+suitable for use on all devices from low power single board computers to
+full servers.
+
+@defvar mosquitto-service-type
+This is the service type for the @url{https://mosquitto.org/,Mosquitto}
+MQTT broker.  Its value is a @code{mosquitto-configuration} (see below).
+@end defvar
+
+@deftp {Data Type} mosquitto-configuration
+This is the configuration for Mosquitto, with the following fields:
+
+@table @asis
+@item @code{package} (default: @code{mosquitto})
+The Mosquitto package to use.
+
+@item @code{config-file} (default: @code{#f})
+The Mosquitto configuration file as a file-like object or the value
+@code{#f} to use the default configuration.
+
+@item @code{user} (default: @code{"mosquitto"})
+Owner of the broker process.
+
+@item @code{group} (default: @code{"mosquitto"})
+Owner's group of the broker process.
+@end table
+@end deftp
+
+@subsubheading Mosquitto Service
+
+@url{https://mosquitto.org/,Mosquitto} is a lightweight message broker
+that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1.  It is
+suitable for use on all devices from low power single board computers to
+full servers.
+
+@defvar mosquitto-service-type
+This is the service type for the @url{https://mosquitto.org/,Mosquitto}
+MQTT broker.  Its value is a @code{mosquitto-configuration} (see below).
+@end defvar
+
+@deftp {Data Type} mosquitto-configuration
+This is the configuration for Mosquitto, with the following fields:
+
+@table @asis
+@item @code{package} (default: @code{mosquitto})
+The Mosquitto package to use.
+
+@item @code{config-file} (default: @code{#f})
+The Mosquitto configuration file as a file-like object or the value
+@code{#f} to use the default configuration.
+
+@item @code{user} (default: @code{"mosquitto"})
+Owner of the broker process.
+
+@item @code{group} (default: @code{"mosquitto"})
+Owner's group of the broker process.
+@end table
+@end deftp
+
 @node Telephony Services
 @subsection Telephony Services
 
diff --git a/gnu/services/messaging.scm b/gnu/services/messaging.scm
index c13700f032..4cfac3bc3a 100644
--- a/gnu/services/messaging.scm
+++ b/gnu/services/messaging.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2015, 2017-2020, 2022-2024 Ludovic Courtès <l...@gnu.org>
 ;;; Copyright © 2018 Pierre-Antoine Rouby <cont...@parouby.fr>
 ;;; Copyright © 2025 Maxim Cournoyer <maxim.courno...@gmail.com>
+;;; Copyright © 2024 Evgeny Pisemsky <m...@pisemsky.site>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -187,7 +188,15 @@
             quassel-service-type
 
             snuik-configuration
-            snuik-service-type))
+            snuik-service-type
+
+            mosquitto-configuration
+            mosquitto-configuration?
+            mosquitto-configuration-package
+            mosquitto-configuration-config-file
+            mosquitto-configuration-user
+            mosquitto-configuration-group
+            mosquitto-service-type))
 
 ;;; Commentary:
 ;;;
@@ -2106,6 +2115,67 @@ for the distributed IRC client quassel, which allows you 
to connect from
 multiple machines simultaneously.")))
 
 
+;;;
+;;; Mosquitto.
+;;;
+
+(define-record-type* <mosquitto-configuration>
+  mosquitto-configuration
+  make-mosquitto-configuration
+  mosquitto-configuration?
+  (package     mosquitto-configuration-package
+               (default mosquitto))
+  (config-file mosquitto-configuration-config-file
+               (default #f))
+  (user        mosquitto-configuration-user
+               (default "mosquitto"))
+  (group       mosquitto-configuration-group
+               (default "mosquitto")))
+
+(define (mosquitto-accounts config)
+  (match-record config <mosquitto-configuration>
+                (user group)
+    (filter identity
+            (list
+             (and (equal? group "mosquitto")
+                  (user-group
+                   (name "mosquitto")
+                   (system? #t)))
+             (and (equal? user "mosquitto")
+                  (user-account
+                   (name "mosquitto")
+                   (group group)
+                   (system? #t)
+                   (comment "bzzz")
+                   (home-directory "/var/empty")
+                   (shell (file-append shadow "/sbin/nologin"))))))))
+
+(define (mosquitto-shepherd-service config)
+  (match-record config <mosquitto-configuration>
+                (package config-file user group)
+    (list (shepherd-service
+           (documentation "Run the Mosquitto MQTT broker.")
+           (provision '(mosquitto))
+           (requirement '(networking syslogd user-processes))
+           (start #~(make-forkexec-constructor
+                     (list #$(file-append package "/sbin/mosquitto")
+                           #$@(if config-file
+                                  (list "-c" config-file)
+                                  '()))
+                     #:user #$user
+                     #:group #$group))
+           (stop #~(make-kill-destructor))))))
+
+(define mosquitto-service-type
+  (service-type
+   (description "Run the Mosquitto MQTT broker.")
+   (name 'mosquitto)
+   (extensions
+    (list (service-extension account-service-type mosquitto-accounts)
+          (service-extension shepherd-root-service-type 
mosquitto-shepherd-service)))
+   (default-value (mosquitto-configuration))))
+
+
 ;;;
 ;;; Snuik.
 ;;;

Reply via email to