From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 0JZQB2OSIGQGKgAASxT56A (envelope-from ) for ; Sun, 26 Mar 2023 20:43:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WFxjBmOSIGQfKgEAG6o9tA (envelope-from ) for ; Sun, 26 Mar 2023 20:43:47 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9CB141EB23 for ; Sun, 26 Mar 2023 20:43:46 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1679856226; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=/pTiBlbUn3ynab+o8nmGoAj4Hvd3J1an9QrpFQeJeTY=; b=uS3HbpDkIX80TVvb3Fw8GyH2zm7sU9L+589rc9zEnlnxAs1RZfKWj/trLBhoLoz/wH029n Kss2vlBouCo4w1qxpdMqWatsDCNImUif+9x57oEhW4wR0cwYJtZVwcmsOx0e/NTlgJq3uh I/7/A8P//th3XBr9hKEjU2L1SXrCSU2Iwh4+3EyivnjHN/Rfufb0ra3Hr9yQUwlx6N8NqH ZMSEHAxIa35dA8xyjiPwR2XppfvP30mM7LgukekNiJLjAR2OcUjYsqJ/8NrZsJgwMGuzog zurOTPUrv7EQYk5YW2IXhM16RCfeSq2xqWU1C6UeGxfviTnq9e3UmKXA+Te1Pg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1679856226; a=rsa-sha256; cv=none; b=TbLgsLomz76p8pRUS8cWITOTo5UI8/W8SqUpb6VYkVEVJKFr/+P1b1DIq5Ceh9+fE+uU2I 3tPfmGTAHDPY0Wi4IudhsyW0gl71lrTfFidG9Cyo3+oWVnvPNTOljIriwMKTtmAjoNvS4N ezbVt6qpl++oEvuBZYW3uhQUJl/4GTx1dPT2GX/PMbGHO0IlvndkxSvIY8Q5YyMQoadQTL JzbmuBXiAztj4J7pX/RPlnaGDr+xhrLs/OJUGYVImElCs1/afn4Wwg0kTAIjWcr+qT9q4X tmpT+VnqDPO+D67kTAAo+JvFgXuWF1vup/LJtc3bhVn6Z2y0NBnKpPvFlWHUfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgVKd-0007JB-6o; Sun, 26 Mar 2023 14:43:07 -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 1pgVKZ-0007Hs-BH for guix-patches@gnu.org; Sun, 26 Mar 2023 14:43:03 -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 1pgVKY-0001Ej-Mi for guix-patches@gnu.org; Sun, 26 Mar 2023 14:43:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pgVKY-0003Bd-J9 for guix-patches@gnu.org; Sun, 26 Mar 2023 14:43:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62298] [PATCH v4 5/5] services: mympd: Use user-account (resp. user-group) for user (resp. group) fields. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 26 Mar 2023 18:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62298 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62298@debbugs.gnu.org Cc: ludo@gnu.org, Bruno Victal , liliana.prikler@gmail.com, maxim.cournoyer@gmail.com Received: via spool by 62298-submit@debbugs.gnu.org id=B62298.167985616112188 (code B ref 62298); Sun, 26 Mar 2023 18:43:02 +0000 Received: (at 62298) by debbugs.gnu.org; 26 Mar 2023 18:42:41 +0000 Received: from localhost ([127.0.0.1]:45805 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgVKD-0003AR-5C for submit@debbugs.gnu.org; Sun, 26 Mar 2023 14:42:41 -0400 Received: from smtpmciv1.myservices.hosting ([185.26.107.237]:50398) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgVK8-00039u-98 for 62298@debbugs.gnu.org; Sun, 26 Mar 2023 14:42:37 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpmciv1.myservices.hosting (Postfix) with ESMTP id ED04120DCE; Sun, 26 Mar 2023 20:42:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id A0E698009B; Sun, 26 Mar 2023 20:42:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting Received: from mail1.netim.hosting ([127.0.0.1]) by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id DNVNKgaByxpr; Sun, 26 Mar 2023 20:42:34 +0200 (CEST) Received: from guix-nuc.home.arpa (bl9-119-177.dsl.telepac.pt [85.242.119.177]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id F390D80098; Sun, 26 Mar 2023 20:42:33 +0200 (CEST) From: Bruno Victal Date: Sun, 26 Mar 2023 19:41:33 +0100 Message-Id: <67074783f51cf8e2d4688f1084f7bb38f5846c40.1679855983.git.mirai@makinata.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: X-Migadu-Queue-Id: 9CB141EB23 X-Spam-Score: -0.03 X-Migadu-Spam-Score: -0.03 X-Migadu-Scanner: scn0.migadu.com List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-TUID: e5hYxkQUR34M * gnu/services/audio.scm (%mympd-user, %mympd-group): New variable. (mympd-user-sanitizer, mympd-group-sanitizer): New procedure. (mympd-configuration)[user, group]: Set value type to user-account (resp. user-group). (mympd-serialize-configuration): Adapt for user-account values in user field. (mympd-accounts): Adapt for user-account (resp. user-group) in user (resp. group) field. --- doc/guix.texi | 4 +-- gnu/services/audio.scm | 70 +++++++++++++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index ff678ca6ec..7695e000a8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -33732,10 +33732,10 @@ Audio Services This is a list of symbols naming Shepherd services that this service will depend on. -@item @code{user} (default: @code{"mympd"}) (type: string) +@item @code{user} (type: user-account) (optional) Owner of the @command{mympd} process. -@item @code{group} (default: @code{"nogroup"}) (type: string) +@item @code{group} (type: user-group) (optional) Owner group of the @command{mympd} process. @item @code{work-directory} (default: @code{"/var/lib/mympd"}) (type: string) diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index 3fd309e45d..76da67944a 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -658,6 +658,48 @@ (define-configuration/no-serialization mympd-ip-acl (define-maybe/no-serialization integer) (define-maybe/no-serialization mympd-ip-acl) +(define %mympd-user + (user-account + (name "mympd") + (group "mympd") + (system? #t) + (comment "myMPD user") + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin")))) + +(define %mympd-group + (user-group + (name "mympd") + (system? #t))) + +;;; TODO: Procedures for unsupported value types, to be removed. +(define (mympd-user-sanitizer value) + (cond ((user-account? value) value) + ((string? value) + (warning (G_ "string value for 'user' is not supported, use \ +user-account instead~%")) + (user-account + (inherit %mympd-user) + (name value) + ;; XXX: this is to be lazily substituted in (…-accounts) + ;; with the value from 'group'. + (group %lazy-group))) + (else + (configuration-field-error #f 'user value)))) + +(define (mympd-group-sanitizer value) + (cond ((user-group? value) value) + ((string? value) + (warning (G_ "string value for 'group' is not supported, use \ +user-group instead~%")) + (user-group + (inherit %mympd-group) + (name value))) + (else + (configuration-field-error #f 'group value)))) +;;; + + ;; XXX: The serialization procedures are insufficient since we require ;; access to multiple fields at once. ;; Fields marked with empty-serializer are never serialized and are @@ -675,13 +717,15 @@ (define-configuration/no-serialization mympd-configuration empty-serializer) (user - (string "mympd") + (user-account %mympd-user) "Owner of the @command{mympd} process." + (sanitizer mympd-user-sanitizer) empty-serializer) (group - (string "nogroup") + (user-group %mympd-group) "Owner group of the @command{mympd} process." + (sanitizer mympd-group-sanitizer) empty-serializer) (work-directory @@ -816,7 +860,8 @@ (define (mympd-shepherd-service config) (match-record config (package shepherd-requirement user work-directory cache-directory log-level log-to) - (let ((log-level* (format #f "MYMPD_LOGLEVEL=~a" log-level))) + (let ((log-level* (format #f "MYMPD_LOGLEVEL=~a" log-level)) + (username (user-account-name user))) (shepherd-service (documentation "Run the myMPD daemon.") (requirement `(loopback user-processes @@ -826,7 +871,7 @@ (define (mympd-shepherd-service config) ,@shepherd-requirement)) (provision '(mympd)) (start #~(begin - (let* ((pw (getpwnam #$user)) + (let* ((pw (getpwnam #$username)) (uid (passwd:uid pw)) (gid (passwd:gid pw))) (for-each (lambda (dir) @@ -836,8 +881,8 @@ (define (mympd-shepherd-service config) (make-forkexec-constructor `(#$(file-append package "/bin/mympd") - "--user" #$user - #$@(if (eqv? log-to 'syslog) '("--syslog") '()) + "--user" #$username + #$@(if (eq? log-to 'syslog) '("--syslog") '()) "--workdir" #$work-directory "--cachedir" #$cache-directory) #:environment-variables (list #$log-level*) @@ -846,14 +891,11 @@ (define (mympd-shepherd-service config) (define (mympd-accounts config) (match-record config (user group) - (list (user-group (name group) - (system? #t)) - (user-account (name user) - (group group) - (system? #t) - (comment "myMPD user") - (home-directory "/var/empty") - (shell (file-append shadow "/sbin/nologin")))))) + ;; TODO: Deprecation code, to be removed. + (let ((user (if (eq? (user-account-group user) %lazy-group) + (inject-group-into-user user group) + user))) + (list user group)))) (define (mympd-log-rotation config) (match-record config (log-to) -- 2.39.1