From ed111e39aa2d188a146e73251aff63156698bb54 Mon Sep 17 00:00:00 2001
From: Mitchell Schmeisser <mitchellschmeisser@librem.one>
Date: Sat, 27 May 2023 13:22:32 -0400
Subject: [PATCH] home: add gnu/home/services/dict.scm and
home-dicod-service-type
* gnu/home/services/dict.scm: Add home-dicod-service-type
---
gnu/home/services/dict.scm | 84 ++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
create mode 100644 gnu/home/services/dict.scm
new file mode 100644
@@ -0,0 +1,84 @@
+(define-module (gnu home services dict)
+ #:use-module (srfi srfi-1)
+ #:use-module (guix gexp)
+ #:use-module (guix least-authority)
+ #:use-module (gnu build linux-container)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd)
+ #:use-module (gnu packages dictionaries)
+ #:use-module (gnu services dict)
+ #:use-module (gnu system file-systems)
+
+ #:export (%home-dicod-database:gcide
+ %home-dicod-configuration
+ home-dicod-service-type))
+
+(define dico-run-time-dir "/tmp/dico")
+
+(define %home-dicod-database:gcide
+ (dicod-database
+ (name "gcide")
+ (handler "gcide")
+ (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
+ #~(string-append "idxdir=" #$dico-run-time-dir)))))
+
+(define %home-dicod-configuration
+ (dicod-configuration
+ (databases (list %home-dicod-database:gcide))))
+
+(define %home-dicod-activation
+ #~(begin
+ (use-modules (guix build utils))
+ (mkdir-p #$dico-run-time-dir)))
+
+(define (home-dicod-shepherd-service config)
+ (let* ((dicod.conf ((@@ (gnu services dict) dicod-configuration-file) config))
+ (interfaces ((@@ (gnu services dict) dicod-configuration-interfaces) config))
+ (dicod (least-authority-wrapper
+ (file-append
+ ((@@ (gnu services dict) dicod-configuration-dico) config) "/bin/dicod")
+ #:name "dicod"
+ #:mappings (list (file-system-mapping
+ (source dico-run-time-dir)
+ (target source)
+ (writable? #t))
+ (file-system-mapping
+ (source "/dev/log")
+ (target source))
+ (file-system-mapping
+ (source dicod.conf)
+ (target source)))
+ #:namespaces (delq 'net %namespaces))))
+ (list (shepherd-service
+ (provision '(dicod))
+ (documentation "Run the dicod daemon.")
+ (start #~(if (and (defined? 'make-inetd-constructor)
+ #$(= 1 (length interfaces))) ;XXX
+ (make-inetd-constructor
+ (list #$dicod "--inetd" "--foreground"
+ (string-append "--config=" #$dicod.conf))
+ (addrinfo:addr
+ (car (getaddrinfo #$(first interfaces) "dict")))
+ #:service-name-stem "dicod")
+ (make-forkexec-constructor
+ (list #$dicod "--foreground"
+ (string-append "--config=" #$dicod.conf)))))
+ (stop #~(if (and (defined? 'make-inetd-destructor)
+ #$(= 1 (length interfaces))) ;XXX
+ (make-inetd-destructor)
+ (make-kill-destructor)))
+ (actions (list (shepherd-configuration-action dicod.conf)))))))
+
+(define home-dicod-service-type
+ (service-type
+ (name 'home-dicod)
+ (extensions (list (service-extension home-shepherd-service-type
+ home-dicod-shepherd-service)
+ (service-extension home-activation-service-type
+ (const %home-dicod-activation))))
+ (default-value %home-dicod-configuration)
+ (description
+ "Run @command{dicod}, the dictionary server of
+@uref{https://www.gnu.org/software/dico, GNU Dico}. @command{dicod}
+implements the standard DICT protocol supported by clients such as
+@command{dico} and GNOME Dictionary as a user.")))
--
2.39.1