Subject: [bug#56961] [PATCH v2 4/4] gnu: Add home-senpai-service-type.

From: "(" <[email-masked]>
Date: Mon, 10 Oct 2022 17:57:09 +0100

* gnu/local.mk: Add gnu/home/services/irc.scm.
* gnu/home/services/irc.scm (home-senpai-configuration): New
  record type.
(home-senpai-service-type): New variable.
* doc/guix.texi ("Home Configuration")["Home Services"]: Document
  them.
---
 doc/guix.texi             |  87 +++++++++++++++++++++
 gnu/home/services/irc.scm | 154 ++++++++++++++++++++++++++++++++++++++
 gnu/local.mk              |   1 +
 3 files changed, 242 insertions(+)
 create mode 100644 gnu/home/services/irc.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index 14592142dd..f62d84c6e9 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40363,6 +40363,7 @@ services)}.
 * Essential Home Services::  Environment variables, packages, on-* scripts.
 * Shells: Shells Home Services.                        POSIX shells, Bash, Zsh.
 * Mcron: Mcron Home Service.                           Scheduled User's Job Execution.
+* IRC: IRC Home Services.                              Services for Internet Relay Chat.
 * Power Management: Power Management Home Services.    Services for battery power.
 * Shepherd: Shepherd Home Service.                     Managing User's Daemons.
 * SSH: Secure Shell.                                   Setting up the secure shell client.
@@ -40815,6 +40816,92 @@ specifications,, mcron, GNU@tie{}mcron}).
 @end table
 @end deftp
 
+@node IRC Home Services
+@subsection IRC Home Services
+
+@cindex irc
+@cindex messaging
+The @code{(gnu home services irc)} module provides home services for
+Internet Relay Chat-related programs.
+
+@defvr {Scheme Variable} home-senpai-service-type
+Service for configuration of @code{senpai}, a terminal-based IRC client
+that works best with network bouncers such as @code{znc} and @code{soju}.
+@end defvr
+
+@deftp {Data Type} home-senpai-configuration
+Data type representing the configuration of the
+@code{home-senpai-service-type}.
+
+@table @asis
+@item @code{address}
+The address of the IRC server to connect to.
+
+@item @code{nickname}
+A string to use as the IRC nickname.
+
+@item @code{username} (default: @code{#f})
+A string to use as the IRC username.
+
+@item @code{realname} (default: @code{#f})
+A string to use as the IRC real name.
+
+@item @code{password}
+Either a string to use as the IRC password, or a list of strings
+and file-like objects representing a command line that prints the
+password to standard output.
+
+@item @code{channels} (default: @code{#f})
+A list of channels to connect to by default.
+
+@item @code{highlight-words} (default: @code{#f})
+A list of words that, when said by another user, will cause you to
+be ``highlighted'', as if you were mentioned.
+
+@item @code{highlight-beep?} (default: @code{#f})
+Whether to make a sound when you are ``highlighted''.
+
+@item @code{highlight-script} (default: @code{#f})
+A file-like object representing a shell script to be run when you
+are ``highlighted''.  State information is passed to the script via
+the environment; see @command{man senpai.5} for the list of
+variables passed to the script.
+
+@item @code{nicknames-width} (default: @code{14})
+The width of the pane containing the nicknames corresponding to
+each message.
+
+@item @code{channels-width} (default: @code{16})
+The width of the pane containing the list of channels.
+
+@item @code{members-width} (default: @code{16})
+The width of the pane containing the list of channel members.
+
+@item @code{message-width} (default: @code{0})
+The width of the messages.
+
+@item @code{tls?} (default: @code{#t})
+Whether to enable TLS connection support.
+
+@item @code{typing-notify?} (default: @code{#t})
+Whether to send typing notifications to others.
+
+@item @code{mouse?} (default: @code{#t})
+Whether to enable mouse interaction.
+
+@item @code{prompt-color} (default: @code{-1})
+The foreground colour (either an ANSI colour code number or a
+hexadecimal colour string) to use for the ``>'' in the message
+prompt.
+
+@item @code{unread-color} (default: @code{-1})
+The foreground colour to use for buffers with unread messages.
+
+@item @code{debug?} (default: @code{#f})
+Whether to print debugging information to the home message buffer.
+@end table
+@end deftp
+
 @node Power Management Home Services
 @subsection Power Management Home Services
 
diff --git a/gnu/home/services/irc.scm b/gnu/home/services/irc.scm
new file mode 100644
index 0000000000..1097f9a5f0
--- /dev/null
+++ b/gnu/home/services/irc.scm
@@ -0,0 +1,154 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 ( <[email-masked]>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu home services irc)
+  #:use-module (gnu home services)
+  #:use-module (guix gexp)
+  #:use-module (guix packages)
+  #:use-module (guix records)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+
+  #:export (home-senpai-service-type
+            home-senpai-configuration))
+
+;;; Commentary:
+;;;
+;;; This module contains home services for Internet Relay Chat.
+;;;
+;;; Code:
+
+
+;;;
+;;; Senpai.
+;;;
+
+(define-record-type* <home-senpai-configuration>
+  home-senpai-configuration make-home-senpai-configuration
+  home-senpai-configuration?
+  (address home-senpai-address)                  ;string
+  (nickname home-senpai-nickname)                ;string
+  (username home-senpai-username                 ;string | #f
+            (default #f))
+  (realname home-senpai-realname                 ;string | #f
+            (default #f))
+  (password home-senpai-password)                ;string | file-like, list of string
+  (channels home-senpai-channels                 ;list of string | #f
+            (default #f))
+  (highlight-words home-senpai-highlight-words   ;list of string | #f
+                   (default #f))
+  (highlight-beep? home-senpai-highlight-beep?   ;boolean
+                   (default #f))
+  (highlight-script home-senpai-highlight-script ;file-like | #f
+                    (default #f))
+  (nicknames-width home-senpai-nicknames-width   ;integer
+                   (default 14))
+  (channels-width home-senpai-channels-width     ;integer
+                  (default 16))
+  (members-width home-senpai-members-width       ;integer
+                 (default 16))
+  (message-width home-senpai-message-width       ;integer
+                 (default 0))
+  (tls? home-senpai-tls?                         ;boolean
+        (default #t))
+  (typing-notify? home-senpai-typing-notify?     ;boolean
+                  (default #t))
+  (mouse? home-senpai-mouse?                     ;boolean
+          (default #t))
+  (prompt-color home-senpai-prompt-color         ;integer | string
+                (default -1))
+  (unread-color home-senpai-unread-color         ;integer | string
+                (default -1))
+  (debug? home-senpai-debug?                     ;boolean
+          (default #f)))
+
+(define (home-senpai-xdg-configuration-files config)
+  (define (string-field name field)
+    (let ((value (field config)))
+      (if value
+          (list name " \"" value "\"\n")
+          '())))
+
+  (define (string-list-field name field)
+    (let ((value (field config)))
+      (if value
+          (append (list name)
+                  (concatenate (map (cute list " \"" <> "\"") value))
+                  (list "\n"))
+          '())))
+
+  (define (integer-field name field)
+    (let ((value (field config)))
+      (if value
+          (list name " " (number->string value) "\n")
+          '())))
+
+  (define (colour-field name field)
+    (let ((value (field config)))
+      (if (string? value)
+          (string-field name (compose (cute string-append "#" <>)
+                                      field))
+          (integer-field name field))))
+
+  (define (boolean-field name field)
+    (let ((value (field config)))
+      (list name " " (if value "true" "false") "\n")))
+
+  (define (symbol-field name field)
+    (string-field name (compose symbol->string field)))
+
+  (define* (record-field name #:rest fields)
+    (append (list name " {\n")
+            (concatenate fields)
+            (list "}\n")))
+
+  `(("senpai/sen.scfg"
+     ,(apply mixed-text-file "senpai.scfg"
+             (append (string-field "address" home-senpai-address)
+                     (string-field "nickname" home-senpai-nickname)
+                     (string-field "username" home-senpai-username)
+                     (string-field "realname" home-senpai-realname)
+                     (if (list? (home-senpai-password config))
+                         (string-list-field "password-cmd" home-senpai-password)
+                         (string-field "password" home-senpai-password))
+                     (string-list-field "channel" home-senpai-channels)
+                     (string-list-field "highlight" home-senpai-highlight-words)
+                     (boolean-field "on-highlight-beep" home-senpai-highlight-beep?)
+                     (string-field "on-highlight-path" home-senpai-highlight-script)
+                     (record-field "pane-widths"
+                       (integer-field "nicknames" home-senpai-nicknames-width)
+                       (integer-field "channels" home-senpai-channels-width)
+                       (integer-field "members" home-senpai-members-width)
+                       (integer-field "text" home-senpai-message-width))
+                     (boolean-field "tls" home-senpai-tls?)
+                     (boolean-field "typings" home-senpai-typing-notify?)
+                     (boolean-field "mouse" home-senpai-mouse?)
+                     (record-field "colors"
+                       (colour-field "prompt" home-senpai-prompt-color)
+                       (colour-field "unread" home-senpai-unread-color))
+                     (boolean-field "debug" home-senpai-debug?))))))
+
+(define home-senpai-service-type
+  (service-type
+   (name 'home-senpai)
+   (extensions
+    (list (service-extension home-xdg-configuration-files-service-type
+                             home-senpai-xdg-configuration-files)))
+   (description
+    "Configure senpai, a terminal-based IRC client designed for use
+with bouncers.")))
diff --git a/gnu/local.mk b/gnu/local.mk
index 9a1aad300e..3bb4f2a353 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -90,6 +90,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/home/services/symlink-manager.scm		\
   %D%/home/services/fontutils.scm		\
   %D%/home/services/guix.scm			\
+  %D%/home/services/irc.scm			\
   %D%/home/services/pm.scm			\
   %D%/home/services/shells.scm			\
   %D%/home/services/shepherd.scm		\
-- 
2.38.0