From: Mitchell Schmeisser via Guix-patches via <guix-patches@gnu.org>
To: 63758@debbugs.gnu.org
Subject: [bug#63758] home-dicod-service-type gnu/service patch
Date: Mon, 29 May 2023 13:28:18 -0400 [thread overview]
Message-ID: <87edmzcaj1.fsf@librem.one> (raw)
In-Reply-To: <87leh9d6o5.fsf@librem.one>
[-- Attachment #1: 0001-gnu-services-dict.scm-Add-home-dicod-service-type.patch --]
[-- Type: text/x-patch, Size: 7758 bytes --]
From 45c8efc0dbf321cb4cd59ed7f509f241ae8034ce Mon Sep 17 00:00:00 2001
From: Mitchell Schmeisser <mitchellschmeisser@librem.one>
Date: Mon, 29 May 2023 13:21:46 -0400
Subject: [PATCH] gnu/services/dict.scm: Add home-dicod-service-type
---
gnu/services/dict.scm | 71 +++++++++++++++++++++++++++++++++----------
1 file changed, 55 insertions(+), 16 deletions(-)
diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm
index 5a61085..88493ae 100644
--- a/gnu/services/dict.scm
+++ b/gnu/services/dict.scm
@@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
-;;; Copyright © 2016, 2017, 2018, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016, 2017, 2018, 2020, 2022, 2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com>
;;;
;;; This file is part of GNU Guix.
@@ -26,6 +26,8 @@ (define-module (gnu services dict)
#:use-module (guix least-authority)
#:use-module (gnu services)
#:use-module (gnu services shepherd)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd)
#:use-module (gnu system shadow)
#:use-module ((gnu packages admin) #:select (shadow))
#:use-module (gnu packages dico)
@@ -37,10 +39,12 @@ (define-module (gnu services dict)
#:use-module (ice-9 match)
#:export (dicod-service ; deprecated
dicod-service-type
+ home-dicod-service-type
dicod-configuration
dicod-handler
dicod-database
- %dicod-database:gcide))
+ %dicod-database:gcide
+ %home-dicod-database:gcide))
\f
;;;
@@ -56,7 +60,9 @@ (define-record-type* <dicod-configuration>
(handlers dicod-configuration-handlers ;list of <dicod-handler>
(default '()))
(databases dicod-configuration-databases ;list of <dicod-database>
- (default (list %dicod-database:gcide))))
+ (default (list %dicod-database:gcide)))
+ (guix-home? dicod-configuration-guix-home?
+ (default #f)))
(define-record-type* <dicod-handler>
dicod-handler make-dicod-handler
@@ -80,6 +86,13 @@ (define %dicod-database:gcide
(options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
"idxdir=/var/run/dicod"))))
+(define %home-dicod-database:gcide
+ (dicod-database
+ (name "gcide")
+ (handler "gcide")
+ (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
+ "idxdir=/tmp/dicod"))))
+
(define %dicod-accounts
(list (user-group
(name "dicod")
@@ -137,23 +150,30 @@ (define configuration->text
(apply mixed-text-file "dicod.conf" (configuration->text config)))
-(define %dicod-activation
+(define (dicod-activation config)
#~(begin
(use-modules (guix build utils))
- (let ((user (getpwnam "dicod"))
- (rundir "/var/run/dicod"))
+ (let* ((guix-home? #$(dicod-configuration-guix-home? config))
+ (user (if guix-home?
+ (getuid) (getpwnam "dicod")))
+ (rundir (if guix-home?
+ "/tmp/dicod"
+ "/var/run/dicod")))
(mkdir-p rundir)
- (chown rundir (passwd:uid user) (passwd:gid user)))))
+ (unless guix-home?
+ (chown rundir (passwd:uid user) (passwd:gid user))))))
-(define (dicod-shepherd-service config)
- (let* ((dicod.conf (dicod-configuration-file config))
+(define* (dicod-shepherd-service config)
+ (let* ((guix-home? (dicod-configuration-guix-home? config))
+ (rt-dir (if guix-home? "/tmp/dicod" "/var/run/dicod"))
+ (dicod.conf (dicod-configuration-file config))
(interfaces (dicod-configuration-interfaces config))
(dicod (least-authority-wrapper
(file-append (dicod-configuration-dico config)
"/bin/dicod")
#:name "dicod"
#:mappings (list (file-system-mapping
- (source "/var/run/dicod")
+ (source rt-dir)
(target source)
(writable? #t))
(file-system-mapping
@@ -165,21 +185,28 @@ (define (dicod-shepherd-service config)
#:namespaces (delq 'net %namespaces))))
(list (shepherd-service
(provision '(dicod))
- (requirement '(user-processes))
+ (requirement (if guix-home? '() '(user-processes)))
(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")))
- #:user "dicod" #:group "dicod"
+ (list (endpoint
+ (addrinfo:addr
+ (car (getaddrinfo #$(first interfaces)
+ "dict")))))
+ #:requirements '#$requirement
+ #$@(if guix-home?
+ '()
+ '(#:user "dicod" #:group "dicod"))
#:service-name-stem "dicod")
(make-forkexec-constructor
(list #$dicod "--foreground"
(string-append "--config=" #$dicod.conf))
- #:user "dicod" #:group "dicod")))
+ #$@(if guix-home?
+ '()
+ '(#:user "dicod" #:group "dicod")))))
(stop #~(if (and (defined? 'make-inetd-destructor)
#$(= 1 (length interfaces))) ;XXX
(make-inetd-destructor)
@@ -193,7 +220,7 @@ (define dicod-service-type
(list (service-extension account-service-type
(const %dicod-accounts))
(service-extension activation-service-type
- (const %dicod-activation))
+ dicod-activation)
(service-extension shepherd-root-service-type
dicod-shepherd-service)))
(default-value (dicod-configuration))
@@ -203,6 +230,18 @@ (define dicod-service-type
implements the standard DICT protocol supported by clients such as
@command{dico} and GNOME Dictionary.")))
+(define home-dicod-service-type
+ (service-type
+ (inherit dicod-service-type)
+ (extensions (list (service-extension home-shepherd-service-type
+ dicod-shepherd-service)
+ (service-extension home-activation-service-type
+ dicod-activation)))
+ (default-value (dicod-configuration
+ (guix-home? #t)
+ (databases (list %home-dicod-database:gcide))))))
+
+
(define-deprecated (dicod-service #:key (config (dicod-configuration)))
dicod-service-type
"Return a service that runs the @command{dicod} daemon, an implementation
--
2.39.1
[-- Attachment #2: Type: text/plain, Size: 453 bytes --]
Here is an alternate patch which modifies gnu/services/dict.scm to
provide home-dicod-service-type.
This seems better than the code in gnu/home/services/dict.scm which
makes use of a lot of ~(@@ (gnu services dict))~ accessors to parse the
configuration data. I think having home services defined along side
their system counter parts makes it more likely people studying the code
while writing new services will include a home implementation as well.
next prev parent reply other threads:[~2023-05-29 17:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-27 17:29 [bug#63758] home-dicod-service-type Mitchell Schmeisser via Guix-patches via
2023-05-29 17:28 ` Mitchell Schmeisser via Guix-patches via [this message]
2023-08-07 9:48 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87edmzcaj1.fsf@librem.one \
--to=guix-patches@gnu.org \
--cc=63758@debbugs.gnu.org \
--cc=mitchellschmeisser@librem.one \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.