From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 OPqzAOJFHmSCpwAASxT56A (envelope-from ) for ; Sat, 25 Mar 2023 01:52:50 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id IF6kAOJFHmQq0AAAauVa8A (envelope-from ) for ; Sat, 25 Mar 2023 01:52:50 +0100 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 BB1E33ED26 for ; Sat, 25 Mar 2023 01:52:49 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfs8d-00017u-HA; Fri, 24 Mar 2023 20:52: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 1pfs8b-00017V-5W for guix-patches@gnu.org; Fri, 24 Mar 2023 20:52:05 -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 1pfs8a-0007Ja-DF for guix-patches@gnu.org; Fri, 24 Mar 2023 20:52:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pfs8Y-0008Gq-RR for guix-patches@gnu.org; Fri, 24 Mar 2023 20:52:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62298] [PATCH v3 4/5] services: mpd: 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: Sat, 25 Mar 2023 00:52: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.167970547931725 (code B ref 62298); Sat, 25 Mar 2023 00:52:02 +0000 Received: (at 62298) by debbugs.gnu.org; 25 Mar 2023 00:51:19 +0000 Received: from localhost ([127.0.0.1]:41771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pfs7r-0008Fc-9b for submit@debbugs.gnu.org; Fri, 24 Mar 2023 20:51:19 -0400 Received: from smtpm5.myservices.hosting ([185.26.105.236]:41180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pfs7l-0008FB-6y for 62298@debbugs.gnu.org; Fri, 24 Mar 2023 20:51:14 -0400 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpm5.myservices.hosting (Postfix) with ESMTP id ECF8820D40; Sat, 25 Mar 2023 01:51:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 9FD3A8009E; Sat, 25 Mar 2023 01:51:11 +0100 (CET) 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 mMWtEkjI6KtT; Sat, 25 Mar 2023 01:51:11 +0100 (CET) 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 BB9068009B; Sat, 25 Mar 2023 01:51:10 +0100 (CET) From: Bruno Victal Date: Sat, 25 Mar 2023 00:46:47 +0000 Message-Id: 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: 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 ARC-Seal: i=1; s=key1; d=yhetil.org; t=1679705569; a=rsa-sha256; cv=none; b=TcfjIRdUXTyT8QuLVsi5aERSwYbbr0TvBOyPum/G1/h/OePtC5wsmux3epmAA1nWNCTpRk xeZDxx6XuFFKi7U+988cx92OeeCvlE4jgjLUTHUno/nqQiwiyFXQXWw/eucsN/rV96z5ha xs7WlBWVWwut3R4wrzbZMnnyP2TrYOGjk3M+bjMrPB5ET3ycz7J1dLZNgvin+9B2v1sTh7 y8TCuAax+NnxJ1OAT8eZh83SGwD53OXFTXkUuk/VlDpYhMq348AgxlXJaHgMb6SuHiUT9f Xu24np1yHjfXD/alR4wL8Mq4Te4vi1BpCGc09HYhuinqGGk6Yk6ubVmXcBzCLg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1679705569; 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=xwB+4K7Te2WoUDNWjopXISRA5Gq70pjrCJBz9evt+es=; b=P5T0g7Qq6XPE6DO/10PA+WhtCV00ms0ohkSbfNIgMyBbXUqxCnhfkJR3Guy7uG9YW8sekt 6WKG/LtvZbVlXnQ7bUXj3PjQQ/fGXyE4Nl2yPmZC/Qb9Wu1vWv97mXaWpUPKnelHrGp8P7 yu/CoXMBosw6L2ETr/FNV9wK875HifAEV4ZH8366wk2dYCjKJFchcT1I8chRt6dhoA+nQW Ef6DMTZ2WES5OAWvZF51FUDlfFt/Dvqvsb7dlwI6vgUqb7RymW6x9gCUKJH3oThmpgkshd Z91c84rf+9xTApVcPAJwMibKZTFqS1H7yD+zcRMzwN7AeA2kQKYjkWzfbTk+qw== Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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" X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: 0.77 X-Spam-Score: 0.77 X-Migadu-Queue-Id: BB1E33ED26 X-TUID: 4moqZON9fz6W Deprecate using strings for these fields and prefer user-account (resp. user-group) instead to avoid duplication within account-service-type. Fixes #61570 . * gnu/services/audio.scm (mpd-serialize-user-account, mpd-serialize-user-group) (mpd-user-sanitizer, mpd-group-sanitizer): New procedure. (%mpd-user, %mpd-group): New variable. (mpd-configuration)[user, group]: Set value type to user-account (resp. user-group). (mpd-shepherd-service): Adapt for user-account values in user field. (mpd-accounts): Adapt for user-account (resp. user-group) in user (resp. group) field. * doc/guix.texi (Audio Services): Update documentation. --- doc/guix.texi | 4 +- gnu/services/audio.scm | 89 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8604b95f94..10ce098a21 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -33491,10 +33491,10 @@ Audio Services @item @code{package} (default: @code{mpd}) (type: file-like) The MPD package. -@item @code{user} (default: @code{"mpd"}) (type: string) +@item @code{user} (type: maybe-user-account) The user to run mpd as. -@item @code{group} (default: @code{"mpd"}) (type: string) +@item @code{group} (type: maybe-user-group) The group to run mpd as. @item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbol) diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index bc4aed71dc..55749111ab 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -140,6 +140,14 @@ (define (uglify-field-name field-name) (define list-of-symbol? (list-of symbol?)) +;; Helpers for deprecated field types, to be removed later. +(define %lazy-group (make-symbol "%lazy-group")) + +(define (inject-group-into-user user group) + (user-account + (inherit user) + (group (user-group-name group)))) + ;;; ;;; MPD @@ -164,9 +172,32 @@ (define mpd-serialize-boolean mpd-serialize-field) (define (mpd-serialize-list-of-strings field-name value) #~(string-append #$@(map (cut mpd-serialize-string field-name <>) value))) +(define (mpd-serialize-user-account field-name value) + (mpd-serialize-string field-name (user-account-name value))) + +(define (mpd-serialize-user-group field-name value) + (mpd-serialize-string field-name (user-group-name value))) + (define-maybe string (prefix mpd-)) (define-maybe list-of-strings (prefix mpd-)) (define-maybe boolean (prefix mpd-)) +(define-maybe user-account (prefix mpd-)) +(define-maybe user-group (prefix mpd-)) + +(define %mpd-user + (user-account + (name "mpd") + (group "mpd") + (system? #t) + (comment "Music Player Daemon (MPD) user") + ;; MPD can use $HOME (or $XDG_CONFIG_HOME) to place its data + (home-directory "/var/lib/mpd") + (shell (file-append shadow "/sbin/nologin")))) + +(define %mpd-group + (user-group + (name "mpd") + (system? #t))) ;;; TODO: Procedures for deprecated fields, to be removed. @@ -197,6 +228,33 @@ (define (mpd-serialize-port field-name value) (define-maybe port (prefix mpd-)) +;;; Procedures for unsupported value types, to be removed. + +(define (mpd-user-sanitizer value) + (cond ((user-account? value) value) + ((string? value) + (warning (G_ "string value for 'user' is deprecated, use \ +user-account instead~%")) + (user-account + (inherit %mpd-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 (mpd-group-sanitizer value) + (cond ((user-group? value) value) + ((string? value) + (warning (G_ "string value for 'group' is deprecated, use \ +user-group instead~%")) + (user-group + (inherit %mpd-group) + (name value))) + (else + (configuration-field-error #f 'group value)))) + ;;; ;; Generic MPD plugin record, lists only the most prevalent fields. @@ -347,12 +405,14 @@ (define-configuration mpd-configuration empty-serializer) (user - (string "mpd") - "The user to run mpd as.") + (maybe-user-account %mpd-user) + "The user to run mpd as." + (sanitizer mpd-user-sanitizer)) (group - (string "mpd") - "The group to run mpd as.") + (maybe-user-group %mpd-group) + "The group to run mpd as." + (sanitizer mpd-group-sanitizer)) (shepherd-requirement (list-of-symbol '()) @@ -517,7 +577,8 @@ (define (mpd-shepherd-service config) log-file playlist-directory db-file state-file sticker-file environment-variables) - (let* ((config-file (mpd-serialize-configuration config))) + (let ((config-file (mpd-serialize-configuration config)) + (username (user-account-name user))) (shepherd-service (documentation "Run the MPD (Music Player Daemon)") (requirement `(user-processes loopback ,@shepherd-requirement)) @@ -526,7 +587,7 @@ (define (mpd-shepherd-service config) (and=> #$(maybe-value log-file) (compose mkdir-p dirname)) - (let ((user (getpw #$user))) + (let ((user (getpw #$username))) (for-each (lambda (x) (when (and x (not (file-exists? x))) @@ -560,17 +621,11 @@ (define (mpd-shepherd-service config) (define (mpd-accounts config) (match-record config (user group) - (list (user-group - (name group) - (system? #t)) - (user-account - (name user) - (group group) - (system? #t) - (comment "Music Player Daemon (MPD) user") - ;; MPD can use $HOME (or $XDG_CONFIG_HOME) to place its data - (home-directory "/var/lib/mpd") - (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 mpd-service-type (service-type -- 2.39.1