From patchwork Mon May 29 17:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mitchell Schmeisser X-Patchwork-Id: 50445 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 42D7D27BBE2; Mon, 29 May 2023 18:29:19 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3FF2F27BBE9 for ; Mon, 29 May 2023 18:29:17 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3gg3-00077B-DS; Mon, 29 May 2023 13:29:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q3gg2-000773-7g for guix-patches@gnu.org; Mon, 29 May 2023 13:29:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q3gg1-0001Vr-W9 for guix-patches@gnu.org; Mon, 29 May 2023 13:29:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q3gg1-0002V0-Ra for guix-patches@gnu.org; Mon, 29 May 2023 13:29:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63758] home-dicod-service-type gnu/service patch References: <87leh9d6o5.fsf@librem.one> In-Reply-To: <87leh9d6o5.fsf@librem.one> Resent-From: Mitchell Schmeisser Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 29 May 2023 17:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63758 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 63758@debbugs.gnu.org Received: via spool by 63758-submit@debbugs.gnu.org id=B63758.16853813129563 (code B ref 63758); Mon, 29 May 2023 17:29:01 +0000 Received: (at 63758) by debbugs.gnu.org; 29 May 2023 17:28:32 +0000 Received: from localhost ([127.0.0.1]:59078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q3gfX-0002UB-I9 for submit@debbugs.gnu.org; Mon, 29 May 2023 13:28:32 -0400 Received: from mx1.librem.one ([138.201.176.93]:49548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q3gfV-0002Tp-BQ for 63758@debbugs.gnu.org; Mon, 29 May 2023 13:28:30 -0400 Received: from smtp.librem.one (unknown [192.241.214.14]) by mx1.librem.one (Postfix) with ESMTPS id 393D881E4E for <63758@debbugs.gnu.org>; Mon, 29 May 2023 10:28:22 -0700 (PDT) Authentication-Results: name mx1.librem.one; dmarc=fail (p=reject dis=none) header.from=librem.one Date: Mon, 29 May 2023 13:28:18 -0400 Message-ID: <87edmzcaj1.fsf@librem.one> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Mitchell Schmeisser X-ACL-Warn: , Mitchell Schmeisser via Guix-patches X-Patchwork-Original-From: Mitchell Schmeisser via Guix-patches via From: Mitchell Schmeisser Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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. From 45c8efc0dbf321cb4cd59ed7f509f241ae8034ce Mon Sep 17 00:00:00 2001 From: Mitchell Schmeisser 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 -;;; Copyright © 2016, 2017, 2018, 2020, 2022 Ludovic Courtès +;;; Copyright © 2016, 2017, 2018, 2020, 2022, 2023 Ludovic Courtès ;;; Copyright © 2017 Huang Ying ;;; ;;; 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)) ;;; @@ -56,7 +60,9 @@ (define-record-type* (handlers dicod-configuration-handlers ;list of (default '())) (databases dicod-configuration-databases ;list of - (default (list %dicod-database:gcide)))) + (default (list %dicod-database:gcide))) + (guix-home? dicod-configuration-guix-home? + (default #f))) (define-record-type* 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