unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#75021] [PATCH] services: Add mosquitto-service-type.
@ 2024-12-22  9:10 Evgeny Pisemsky
  2024-12-27 15:30 ` Evgeny Pisemsky
  0 siblings, 1 reply; 2+ messages in thread
From: Evgeny Pisemsky @ 2024-12-22  9:10 UTC (permalink / raw)
  To: 75021

[-- Attachment #1: 0001-services-Add-mosquitto-service-type.patch --]
[-- Type: text/x-patch, Size: 5881 bytes --]

From b7dce453fc4dd29309687b2eb5bea99663b44212 Mon Sep 17 00:00:00 2001
Message-ID: <b7dce453fc4dd29309687b2eb5bea99663b44212.1734858256.git.mail@pisemsky.site>
From: Evgeny Pisemsky <mail@pisemsky.site>
Date: Sun, 22 Dec 2024 12:00:50 +0300
Subject: [PATCH] services: Add mosquitto-service-type.

Change-Id: I65c141a1aac4a932a8eead86626e4284346c1d91
---
 doc/guix.texi              | 32 +++++++++++++++++
 gnu/services/messaging.scm | 71 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f7b7569887..55cfbbceac 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -134,6 +134,7 @@
 Copyright @copyright{} 2024 Nigko Yerden@*
 Copyright @copyright{} 2024 Troy Figiel@*
 Copyright @copyright{} 2024 Sharlatan Hellseher@*
+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
@@ -29403,6 +29404,37 @@ Messaging Services
 @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 a914d0f89e..056aa8b207 100644
--- a/gnu/services/messaging.scm
+++ b/gnu/services/messaging.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2015, 2017-2020, 2022-2024 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Pierre-Antoine Rouby <contact@parouby.fr>
+;;; Copyright © 2024 Evgeny Pisemsky <mail@pisemsky.site>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -59,7 +60,15 @@ (define-module (gnu services messaging)
             bitlbee-service-type
 
             quassel-configuration
-            quassel-service-type))
+            quassel-service-type
+
+            mosquitto-configuration
+            mosquitto-configuration?
+            mosquitto-configuration-package
+            mosquitto-configuration-config-file
+            mosquitto-configuration-user
+            mosquitto-configuration-group
+            mosquitto-service-type))
 
 ;;; Commentary:
 ;;;
@@ -1002,3 +1011,63 @@ (define quassel-service-type
                  "Run @url{https://quassel-irc.org/,quasselcore}, the backend
 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))))

base-commit: 02e6fa8f923849afa0d46f81262936880000664f
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [bug#75021] [PATCH] services: Add mosquitto-service-type.
  2024-12-22  9:10 [bug#75021] [PATCH] services: Add mosquitto-service-type Evgeny Pisemsky
@ 2024-12-27 15:30 ` Evgeny Pisemsky
  0 siblings, 0 replies; 2+ messages in thread
From: Evgeny Pisemsky @ 2024-12-27 15:30 UTC (permalink / raw)
  To: 75021

[-- Attachment #1: Type: text/plain, Size: 46 bytes --]

I have described changes in a commit message.

[-- Attachment #2: 0001-services-Add-mosquitto-service-type.patch --]
[-- Type: text/x-patch, Size: 6130 bytes --]

From 06968ec1b2849441633be2392160dc2793e676ac Mon Sep 17 00:00:00 2001
Message-ID: <06968ec1b2849441633be2392160dc2793e676ac.1735312937.git.mail@pisemsky.site>
From: Evgeny Pisemsky <mail@pisemsky.site>
Date: Fri, 27 Dec 2024 18:18:01 +0300
Subject: [PATCH] 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: I65c141a1aac4a932a8eead86626e4284346c1d91
---
 doc/guix.texi              | 32 +++++++++++++++++
 gnu/services/messaging.scm | 71 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index da4d2f5ebc..80ebfe4cae 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -134,6 +134,7 @@
 Copyright @copyright{} 2024 Nigko Yerden@*
 Copyright @copyright{} 2024 Troy Figiel@*
 Copyright @copyright{} 2024 Sharlatan Hellseher@*
+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
@@ -29414,6 +29415,37 @@ Messaging Services
 @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 a914d0f89e..056aa8b207 100644
--- a/gnu/services/messaging.scm
+++ b/gnu/services/messaging.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2015, 2017-2020, 2022-2024 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Pierre-Antoine Rouby <contact@parouby.fr>
+;;; Copyright © 2024 Evgeny Pisemsky <mail@pisemsky.site>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -59,7 +60,15 @@ (define-module (gnu services messaging)
             bitlbee-service-type
 
             quassel-configuration
-            quassel-service-type))
+            quassel-service-type
+
+            mosquitto-configuration
+            mosquitto-configuration?
+            mosquitto-configuration-package
+            mosquitto-configuration-config-file
+            mosquitto-configuration-user
+            mosquitto-configuration-group
+            mosquitto-service-type))
 
 ;;; Commentary:
 ;;;
@@ -1002,3 +1011,63 @@ (define quassel-service-type
                  "Run @url{https://quassel-irc.org/,quasselcore}, the backend
 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))))

base-commit: 831b94a1efcea8f793afc949b5123a6235c9bb1a
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-27 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-22  9:10 [bug#75021] [PATCH] services: Add mosquitto-service-type Evgeny Pisemsky
2024-12-27 15:30 ` Evgeny Pisemsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).