From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id QPNxCmLrS2QyhAEASxT56A (envelope-from ) for ; Fri, 28 Apr 2023 17:50:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id +KxbCWLrS2TAkwAAG6o9tA (envelope-from ) for ; Fri, 28 Apr 2023 17:50:58 +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 D340738F0B for ; Fri, 28 Apr 2023 17:50:57 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psP5H-00087r-7K; Fri, 28 Apr 2023 10:28:27 -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 1psP4z-0007bx-3D for bug-guix@gnu.org; Fri, 28 Apr 2023 10:28:12 -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 1psP4y-00060h-Rj for bug-guix@gnu.org; Fri, 28 Apr 2023 10:28:08 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1psP4y-0005AJ-NJ for bug-guix@gnu.org; Fri, 28 Apr 2023 10:28:08 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63082: [PATCH 15/17] services: mpd: Provision a default cache directory and set HOME. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 28 Apr 2023 14:28:08 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63082 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63082@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 63082-submit@debbugs.gnu.org id=B63082.168269208819834 (code B ref 63082); Fri, 28 Apr 2023 14:28:08 +0000 Received: (at 63082) by debbugs.gnu.org; 28 Apr 2023 14:28:08 +0000 Received: from localhost ([127.0.0.1]:34174 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psP4x-00059Z-6s for submit@debbugs.gnu.org; Fri, 28 Apr 2023 10:28:07 -0400 Received: from mail-qk1-f180.google.com ([209.85.222.180]:62758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1psP4Z-00055p-T0 for 63082@debbugs.gnu.org; Fri, 28 Apr 2023 10:27:44 -0400 Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-75131c2997bso635580885a.1 for <63082@debbugs.gnu.org>; Fri, 28 Apr 2023 07:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682692058; x=1685284058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4MRX8aoiUGdan7giiWUWwNbOOWjzJJvCk+9FJSk+9jo=; b=Uq6S4ltVNquZalgeKpYKTnaeie/wRYKw4VdWRP0vse55iq3RqehifIVdyBPOKwDAgP 49oJ1DHenTfnCir58g8UODDrqiuA+PBq+fnoD4YkBapmG5RKdOfEcZ2G+BxmGTbC2t6G Kx1TcxUsb2DlfDH80AFwBhIfKppTvn0+twtk9u0WUye2stLJJXTwpf5nktfiQBXfvKJx FOUbwCkYgWxIVSBXzKDInchafmQwn/3ifpSLa7ZQxps7hPHUBu27wrKpQoqgpvqZXWHL l6BK/Dic0DHFkuY4zi1FQmfq8LVufPW2um8NqRUwm+VcAChwRN/BTjXCjhg+YLUQ0F9g 4Tpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682692058; x=1685284058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4MRX8aoiUGdan7giiWUWwNbOOWjzJJvCk+9FJSk+9jo=; b=MOdm8ubBB+pryMGkX1j6TBhuAcayfTciiCGPMwbEkJtYHyUG0hX5BE0AKlU+JjxQo/ 6zERC75zZS+d0Ucf5nLMBciIGlb/OfkgWZ7tdEmJFScI6U7Az4ShdED/TKC6ybMwlF/3 zFtufKLTtwQvt/D2KgGVk92NYYmRoeh/jJwMEbXQ65aY9mh+y1q/lnzDNCSMNdvSFXl+ u7Db18mZj4w+6CaqcpSXwfwe7iwrfAloLRL7DYDljq4Yh7+amL7wpnf+zBV2JNbd4TCC O1qA4qIuSapcEekgM1mjz0GeZN4BP1QuSfMgvjJDL9GUIxrMmgKi5a8HGK1AYcgenqeU G82w== X-Gm-Message-State: AC+VfDzWRIqnUJ1H7k0K1RHciEDRN+y69XeOJTyMuRrzPLXrZRZngl4S U8RvyUeqKoyLYrlhkSe3RqeVHdfyg3w= X-Google-Smtp-Source: ACHHUZ7LSHb8AxLpm7lrQGVgJsp2Yx7MlMpFTvnx+jDsEuPaP1Fdppr5gMtr7pm2bRSCzeK+0mAxhA== X-Received: by 2002:ad4:5de4:0:b0:5f1:6aa8:cd2d with SMTP id jn4-20020ad45de4000000b005f16aa8cd2dmr9052932qvb.22.1682692058316; Fri, 28 Apr 2023 07:27:38 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1000]) by smtp.gmail.com with ESMTPSA id d8-20020a0cfe88000000b005ff569bca72sm6176940qvs.93.2023.04.28.07.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 07:27:38 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 28 Apr 2023 10:27:08 -0400 Message-Id: <3baf1982e8435b4a3ef13c050153d505b98fa52a.1682690696.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-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=1682697057; a=rsa-sha256; cv=none; b=IfZ7qGmYLhI2j5GNzgEicXYZL5aPDkykgdm9+DDgbBVuom97Y+clKhtw1QvPi1qVm7ohcK nXFL4gqdb2s+ke4YObHLpCeU2ZtHQ47LASN5jBiqWetvbFiw8wytwnhk5R3WDsylbfYh1S Jt6tGmqpZt5MOifwOxW5k4P8XzEdap8REsyY/bjtd7G9kUReIS5J22NqSlDPEVTxpjv/Gc T5E9g/r+3PRgd0PuvgsRse+t2yeag2vWJ0tkHOQhhqV5Y6DsGL8miL6TvO+nscOjuVojkb S3ub/KJ3S9/3Owly9gv0hgo2a7RCTN0lllusWIE7Kk/chMi5exgPEr49VNeg2Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=Uq6S4ltV; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1682697057; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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:dkim-signature; bh=4MRX8aoiUGdan7giiWUWwNbOOWjzJJvCk+9FJSk+9jo=; b=qIID9yUY6O2luIimea7cis/bnjDBX4QtUkSA2UswujPvx1IvxbzPd8+dFwDWbUs1Sh/YY1 s6k1jtCvVCCYVKVIfFyDKzNAKTEgD6luG+HyXhwwb1f/utBW9eI57qcfUWYJy25gqr2gko ib8Obq4HUx+35yrWunB7s4m6R2H7odvRRRgmm/SH81aWl6SQuCEef4zRZezmBMX0mjv3ap Vd1wm14hOonlLPIaI/8xydTRGT/4ylSTtyrh4oli6WVr6VYLDgkFrtiRfKE/uQ1PZHf126 c+TGJC3PkPz2LWzFC72e86rQaHfaCUc38zm7S15Wl1h81Buvpd11/ROfimTb7g== X-Migadu-Spam-Score: -2.70 X-Spam-Score: -2.70 X-Migadu-Queue-Id: D340738F0B X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=Uq6S4ltV; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-TUID: 3YGJD4SIVJGX Relates to . * gnu/services/audio.scm (mpd-shepherd-service): Create a default .cache directory. Use mkdir-p/perms and refactor loop. Set the HOME environment variables. --- doc/guix.texi | 3 +- gnu/services/audio.scm | 76 ++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 23f3070f39..9be59f9f02 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -33603,7 +33603,8 @@ Audio Services The directory to store playlists. @item @code{db-file} (type: maybe-string) -The location of the music database. +The location of the music database. When left unspecified, +@file{~/.cache/db} is used. @item @code{state-file} (type: maybe-string) The location of the file that stores current MPD's state. diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index f0587b9106..7c577ff73b 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -25,6 +25,7 @@ (define-module (gnu services audio) #:use-module (guix deprecation) #:use-module (guix diagnostics) #:use-module (guix i18n) + #:use-module (guix modules) #:use-module (gnu services) #:use-module (gnu services admin) #:use-module (gnu services configuration) @@ -463,7 +464,8 @@ (define-configuration mpd-configuration (db-file maybe-string - "The location of the music database.") + "The location of the music database. When left unspecified, +@file{~/.cache/db} is used.") (state-file maybe-string @@ -597,34 +599,50 @@ (define (mpd-shepherd-service config) (documentation "Run the MPD (Music Player Daemon)") (requirement `(user-processes loopback ,@shepherd-requirement)) (provision '(mpd)) - (start #~(begin - (let ((user (getpw #$username))) - (for-each - (lambda (x) - ;; Take action on absolute file names, to filter out - ;; the 'syslog' special value. - (when (and x (string-prefix? "/" x) - (not (file-exists? x))) - (mkdir-p x) - (chown x (passwd:uid user) (passwd:gid user)))) - (list #$(maybe-value playlist-directory) - (and=> #$(maybe-value db-file) dirname) - (and=> #$(maybe-value log-file) dirname) - (and=> #$(maybe-value state-file) dirname) - (and=> #$(maybe-value sticker-file) dirname)))) - - (make-forkexec-constructor - (list #$(file-append package "/bin/mpd") - "--no-daemon" - #$config-file) - #:environment-variables - ;; Use the system-configured pulse configuration. - (list "PULSE_CLIENTCONFIG=/etc/pulse/client.conf" - "PULSE_CONFIG=/etc/pulse/daemon.conf") - #:user #$username - #:group #$(user-account-group user) - #:supplementary-groups - '#$(user-account-supplementary-groups user)))) + (start + (with-imported-modules (source-module-closure + '((gnu build activation))) + #~(begin + (use-modules (gnu build activation)) + + (let ((home #$(user-account-home-directory user))) + (let ((user (getpw #$username)) + (default-cache-dir (string-append home "/.cache"))) + + (define (init-directory directory) + (unless (file-exists? directory) + (mkdir-p/perms directory user #o755))) + + ;; Define a cache location that can be automatically used + ;; for the database file, in case it hasn't been explicitly + ;; specified. + (for-each + init-directory + (cons default-cache-dir + '#$(map dirname + ;; XXX: Delete the potential "syslog" + ;; log-file value, which is not a directory. + (delete "syslog" + (filter-map maybe-value + (list db-file + log-file + state-file + sticker-file))))))) + + (make-forkexec-constructor + (list #$(file-append package "/bin/mpd") "--no-daemon" + #$config-file) + #:environment-variables + ;; Use the system-configured pulse configuration. Set HOME + ;; so MPD can infer default paths, such as for the database + ;; file. + (list (string-append "HOME=" home) + "PULSE_CLIENTCONFIG=/etc/pulse/client.conf" + "PULSE_CONFIG=/etc/pulse/daemon.conf") + #:user #$username + #:group #$(user-account-group user) + #:supplementary-groups + '#$(user-account-supplementary-groups user)))))) (stop #~(make-kill-destructor)) (actions (list (shepherd-configuration-action config-file) -- 2.39.2