Subject: [bug#61483] [PATCH v2 3/5] DRAFT gnu: home: services: Add home-znc-service-type.

From: "Jan (janneke) Nieuwenhuizen" <[email-masked]>
Date: Thu, 16 Feb 2023 16:53:53 +0100

* gnu/home/services/shepherd-xyz.scm
(<home-znc-configuration>): New type.
(home-znc-services): New procedure.
(home-znc-service-type): New variable.
---
 gnu/home/services/shepherd-xyz.scm | 43 +++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/gnu/home/services/shepherd-xyz.scm b/gnu/home/services/shepherd-xyz.scm
index 75f3770ffc..856a5e7246 100644
--- a/gnu/home/services/shepherd-xyz.scm
+++ b/gnu/home/services/shepherd-xyz.scm
@@ -25,6 +25,7 @@ (define-module (gnu home services shepherd-xyz)
 
   #:use-module (gnu home services)
   #:use-module (gnu home services shepherd)
+  #:use-module (gnu packages messaging)
   #:use-module (gnu packages ssh)
   #:use-module (gnu packages version-control)
   #:use-module (gnu services configuration)
@@ -35,7 +36,9 @@ (define-module (gnu home services shepherd-xyz)
   #:export (home-git-daemon-configuration
             home-git-daemon-service-type
             home-ssh-agent-configuration
-            home-ssh-agent-service-type))
+            home-ssh-agent-service-type
+            home-znc-configuration
+            home-znc-service-type))
 
 ;;; Commentary:
 ;;
@@ -178,3 +181,41 @@ (define home-ssh-agent-service-type
                              home-ssh-agent-services)))
    (description
     "Install and configure the ssh-agent as a shepherd service.")))
+
+
+;;;
+;;; Znc.
+;;;
+(define-record-type* <home-znc-configuration>
+  home-znc-configuration make-home-znc-configuration
+  home-znc-configuration?
+  (znc           home-znc-znc           ;string
+                 (default znc))
+  (extra-options home-znc-extra-options ;list of string
+                 (default '())))
+
+(define (home-znc-services config)
+  "Return a <shepherd-service> for znc with CONFIG."
+  (match config
+    (($ <home-znc-configuration> znc extra-options)
+     (let* ((znc (file-append znc "/bin/znc"))
+            (command `(,znc
+                       "--foreground"
+                       ,@extra-options))
+            (log-file (string-append %user-log-dir "/znc.log")))
+       (list (shepherd-service
+              (documentation "Run the znc IRC bouncer.")
+              (provision '(znc))
+              (start #~(make-forkexec-constructor '#$command
+                                                  #:log-file #$log-file))
+              (stop #~(make-kill-destructor))))))))
+
+(define home-znc-service-type
+  (service-type
+   (name 'home-znc)
+   (default-value (home-znc-configuration))
+   (extensions
+    (list (service-extension home-shepherd-service-type
+                             home-znc-services)))
+   (description
+    "Install and configure znc as a shepherd service.")))
-- 
2.38.1