From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id KJDYFC/YHGNkAQEAbAwnHQ (envelope-from ) for ; Sat, 10 Sep 2022 20:32:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id AFGzFC/YHGMuMwAAauVa8A (envelope-from ) for ; Sat, 10 Sep 2022 20:32:15 +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 DCAEC9EE3 for ; Sat, 10 Sep 2022 20:32:14 +0200 (CEST) Received: from localhost ([::1]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oX5H4-0007gV-2o for larch@yhetil.org; Sat, 10 Sep 2022 14:32:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oX5Gt-0007g8-7u for guix-patches@gnu.org; Sat, 10 Sep 2022 14:32:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oX5Gs-0006Oz-Mn for guix-patches@gnu.org; Sat, 10 Sep 2022 14:32:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oX5Gs-0001Ix-8L for guix-patches@gnu.org; Sat, 10 Sep 2022 14:32:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54986] [PATCH v3 2/2] services: mpd: Support socket activation. References: <9d4cc9d3ebb05d2aabf8f06e1890efe9b0b9a849.camel@gmail.com> In-Reply-To: <9d4cc9d3ebb05d2aabf8f06e1890efe9b0b9a849.camel@gmail.com> Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 10 Sep 2022 18:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54986 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54986@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxime Devos Received: via spool by 54986-submit@debbugs.gnu.org id=B54986.16628347114988 (code B ref 54986); Sat, 10 Sep 2022 18:32:02 +0000 Received: (at 54986) by debbugs.gnu.org; 10 Sep 2022 18:31:51 +0000 Received: from localhost ([127.0.0.1]:40387 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX5Gh-0001IN-0y for submit@debbugs.gnu.org; Sat, 10 Sep 2022 14:31:51 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42700) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX5Gf-0001IA-Nm for 54986@debbugs.gnu.org; Sat, 10 Sep 2022 14:31:50 -0400 Received: by mail-ed1-f66.google.com with SMTP id q21so7128836edc.9 for <54986@debbugs.gnu.org>; Sat, 10 Sep 2022 11:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:content-transfer-encoding:cc:to:subject :date:from:from:to:cc:subject:date; bh=DfLDIrAOK4qB4Pw7AgXES9F2QW50ZL1LQTEWIvogyp8=; b=Qq2NZJp+N7pKXff7GidlgdMKnug72RJoJkffqd19n1jNtbrzn9Ug9rkDxgrWg3jaop O5FUYCYbbDWyp/Zvyc8/daIMYwQYmoFlu9WccOCL8bCe0MynVoKRW0aNE1mayV96DEuU nEBTOPMxKy7qJbme8YMlQmIp4PBKH7In/FWYiCJJReP1Wls0Id08I5ZV4wXNjjTIPr/R FxewcR0zGOhw6OkqxCf+78tTOfhqnVjanMhguaaOTlXpJwcA25FDP7fJaZz9TycIqHxK Qv53KqVgx14y3wItnnUA5PzX+voP+0ZNGu7b4rMT+QYNXm+GsldyNYzOt1uKt2UPuCn5 p8WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:content-transfer-encoding:cc:to:subject :date:from:x-gm-message-state:from:to:cc:subject:date; bh=DfLDIrAOK4qB4Pw7AgXES9F2QW50ZL1LQTEWIvogyp8=; b=jNoictNz8ZWYyCZJDMr3q3IIvktpLmqSefhc3vyBa6+j5BchS7Nh7lAfPgwYDOTsuf ULnc1DFqkPxDU7CqjBOv958NK6vanF6yU7ltyR06Gt2Pa5wJq6c/k52E4aZGCPikq5/9 YYYYSMfk6bf60tlvhFln89PL/YOsMgF5scTMpfb1fAji0DEk80CMik/pSDs/J++M0CRY 1vgBzxBbb5IUtYkY9Vrr/ShyfZdJIJeS/eKUdqZl03QmDL/8wxQnuMztqDYxiorSiusW Th/hLjWWtr3aEuIZAWE4T4aNetl+7CbTBNwFcTLH9PKX400XbWReobsa6tPJHwx/DK4j +LLQ== X-Gm-Message-State: ACgBeo3WftsaxmrczvLcDA5Znez+S48EeHVtq3gImtw6nT3S6mkWiEvI ADG10pj6+40pB1f7xgfcFR0bVrRJwQM= X-Google-Smtp-Source: AA6agR6uotoEaYa0zjQOT2iM+fw7IcorRjz5GKUuzc9cS+M6bPf84AVBwndcPyVkK+wV7VL0M0QmUQ== X-Received: by 2002:a05:6402:22c7:b0:451:403e:68f5 with SMTP id dm7-20020a05640222c700b00451403e68f5mr3791486edb.242.1662834703711; Sat, 10 Sep 2022 11:31:43 -0700 (PDT) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id v12-20020a056402348c00b0043bbb3535d6sm2599993edc.66.2022.09.10.11.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 11:31:43 -0700 (PDT) From: Liliana Marie Prikler Date: Sat, 23 Apr 2022 16:39:59 +0200 Content-Transfer-Encoding: 7bit Message-ID: <3105812906c619735df4a5f476c1c822c63bfb15.camel@gmail.com> MIME-Version: 1.0 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1662834735; 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=DfLDIrAOK4qB4Pw7AgXES9F2QW50ZL1LQTEWIvogyp8=; b=DtBhlKC+rs3bRO5aEbPwRN/Z3BJMc1bQ7HU9YHW1AvIj1ytOJsciooPuX+/pNyoOaZxfJ4 iLIWvjs1ll8di8eVP0gu+wpLGNkXke/QzmmFDWW7yJstCKLU87iVAHkipCrnX7MW6IUzMp TH5npyfv1VUcRiXzibM2hPxxcgbAMel3OMZsNJpVUI2LziqyCWX//U7dTYHHoj8BPhX9Iq 656eoQTjNWNpCNkXIPMBQ4Y3i8EsSuUqRVYKEGC17eIcXp7Ajlo+ax9ADLENeZaod/pZgR IzZ7mveUV9gH13ZVLhjGK5bO04SMn5MVTGxcLR/lMssyIPD1Kr+j53Afn8LJsA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662834735; a=rsa-sha256; cv=none; b=Y15acehKGY3c788PSPwWnnICHVazGyPdOMSqV+eJjY52j4HtjhGbJGF3gE/vACZ6gxbIK/ DWa2sTrpQC+14/YP78tdUghasKuu/QbdrCiH2Wfv5GM7dhtXZpJMdWkW9Dcvp303aOX49J Xz43tQ5WyYzUezkwfMda1u6BrMdDl7NjHYi3Ux8JjAB//Q4T2XOr419RrbjeZtVcMia4WV alOgVCr3ZKDxc0A0NcJvft7x+N2NuSKpjeIFIDLhieqjgkkqjFovWzfsJ6qZ2KLwLfDb9b 4/7w1QMN2tNgIO9LArCh3Mz6n6erUYjkpk+fEZV+08u2Vndr2SvCOPAAYVSEvA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=Qq2NZJp+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=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-Spam-Score: 6.71 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=Qq2NZJp+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=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-Queue-Id: DCAEC9EE3 X-Spam-Score: 6.71 X-Migadu-Scanner: scn0.migadu.com X-TUID: y5iIPyq20uDN * gnu/services/audio.scm (): New record. ()[port, address]: Removed fields. [endpoints]: New field. (sanitize-mpd-endpoints, mpd-configuration-shepherd-endpoints): New variables. (mpd-shepherd-service): Use mpd-configuration-shepherd-endpoints. * doc/guix.texi (Music Player Daemon): Document it. --- doc/guix.texi | 23 ++++++++-- gnu/services/audio.scm | 98 +++++++++++++++++++++++++++++++++--------- 2 files changed, 97 insertions(+), 24 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 30cc3b6d45..d5b9de0de2 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -32192,15 +32192,30 @@ The location of the file that stores current MPD's state. @item @code{sticker-file} (default: @code{"~/.mpd/sticker.sql"}) The location of the sticker database. -@item @code{port} (default: @code{"6600"}) -The port to run mpd on. +@item @code{endpoints} (default: @code{(list (mpd-endpoint))}) +The endpoints to bind MPD to. This can be an mpd-endpoint (see below) +or a list of shepherd endpoints. If using shepherd endpoints, MPD +will be spawned as a systemd-style service rather than as a +forkexec-style one. This delays the start of MPD until the first client +connects. + +@item @code{outputs} (default: @code{"(list (mpd-output))"}) +The audio outputs that MPD can use. By default this is a single output using pulseaudio. + +@end table +@end deftp + +@deftp {Data Type} mpd-endpoint +Data type representing the configuration of @command{mpd}. + +@table @asis @item @code{address} (default: @code{"any"}) The address that mpd will bind to. To use a Unix domain socket, an absolute path can be specified here. -@item @code{outputs} (default: @code{"(list (mpd-output))"}) -The audio outputs that MPD can use. By default this is a single output using pulseaudio. +@item @code{port} (default: @code{"6600"}) +The port to run mpd on. @end table @end deftp diff --git a/gnu/services/audio.scm b/gnu/services/audio.scm index c60053f33c..6e8fd460a1 100644 --- a/gnu/services/audio.scm +++ b/gnu/services/audio.scm @@ -20,6 +20,8 @@ (define-module (gnu services audio) #:use-module (guix gexp) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (gnu services) #:use-module (gnu services shepherd) #:use-module (gnu system shadow) @@ -28,8 +30,14 @@ (define-module (gnu services audio) #:use-module (guix records) #:use-module (ice-9 match) #:use-module (ice-9 format) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:export (mpd-output mpd-output? + mpd-endpoint + mpd-endpoint? mpd-configuration mpd-configuration? mpd-service-type)) @@ -59,6 +67,30 @@ (define-record-type* (extra-options mpd-output-extra-options (default '()))) +(define-record-type* + mpd-endpoint make-mpd-endpoint + mpd-endpoint? + (address mpd-endpoint-address (default "any")) + (port mpd-endpoint-port (default "6600"))) + +(define-with-syntax-properties (sanitize-mpd-endpoints (endpoints properties)) + (match endpoints + ((? mpd-endpoint? endpoint) (list endpoint)) + (((? mpd-endpoint?)) endpoints) + (((? mpd-endpoint?) . _) + (raise (make-compound-condition + (condition (&message + (message + (G_ "\ + is mutually exclusive with other endpoints.")))) + (condition (&error-location + (location (source-properties->location properties)))) + (condition (&fix-hint + (hint "\ +Make sure you only need one endpoint or use shepherd endpoints instead.")))))) + (((? shepherd-endpoint?) . (? (cute every shepherd-endpoint? <>))) + endpoints))) + (define-record-type* mpd-configuration make-mpd-configuration mpd-configuration? @@ -74,10 +106,9 @@ (define-record-type* (default "~/.mpd/state")) (sticker-file mpd-configuration-sticker-file (default "~/.mpd/sticker.sql")) - (port mpd-configuration-port - (default "6600")) - (address mpd-configuration-address - (default "any")) + (endpoints mpd-configuration-endpoints ; list of + (default (list (mpd-endpoint))) ; | + (sanitize sanitize-mpd-endpoints)) (outputs mpd-configuration-outputs (default (list (mpd-output))))) @@ -124,9 +155,12 @@ (define (mpd-config->file config) ("playlist_directory" ,mpd-configuration-playlist-dir) ("db_file" ,mpd-configuration-db-file) ("state_file" ,mpd-configuration-state-file) - ("sticker_file" ,mpd-configuration-sticker-file) - ("port" ,mpd-configuration-port) - ("bind_to_address" ,mpd-configuration-address)))))) + ("sticker_file" ,mpd-configuration-sticker-file))) + (match (mpd-configuration-endpoints config) + (($ address port) + `(("bind_to_address" ,address) + ("port" ,port))) + (_ '()))))) (define (mpd-file-name config file) "Return a path in /var/run/mpd/ that is writable @@ -135,24 +169,48 @@ (define (mpd-file-name config file) (mpd-configuration-user config) "/" file)) +(define (mpd-configuration-shepherd-endpoints config) + "Return @code{(mpd-configuration-endpoints config)}" + (let ((endpoints (mpd-configuration-endpoints config))) + (match endpoints + (((? shepherd-endpoint?) . _) endpoints) + (_ #f)))) + (define (mpd-shepherd-service config) (shepherd-service (documentation "Run the MPD (Music Player Daemon)") (requirement '(user-processes)) (provision '(mpd)) - (start #~(make-forkexec-constructor - (list #$(file-append mpd "/bin/mpd") - "--no-daemon" - #$(mpd-config->file config)) - #:environment-variables - ;; Required to detect PulseAudio when run under a user account. - (list (string-append - "XDG_RUNTIME_DIR=/run/user/" - (number->string - (passwd:uid - (getpwnam #$(mpd-configuration-user config)))))) - #:log-file #$(mpd-file-name config "log"))) - (stop #~(make-kill-destructor)))) + (start (if (mpd-configuration-shepherd-endpoints config) + #~(make-systemd-constructor + (list #$(file-append mpd "/bin/mpd") + "--systemd" + #$(mpd-config->file config)) + (list #$@(map shepherd-endpoint->sexp + (mpd-configuration-shepherd-endpoints config))) + #:environment-variables + ;; Required to detect PulseAudio when run under a user account. + (list (string-append + "XDG_RUNTIME_DIR=/run/user/" + (number->string + (passwd:uid + (getpwnam #$(mpd-configuration-user config)))))) + #:log-file #$(mpd-file-name config "log")) + #~(make-forkexec-constructor + (list #$(file-append mpd "/bin/mpd") + "--no-daemon" + #$(mpd-config->file config)) + #:environment-variables + ;; Required to detect PulseAudio when run under a user account. + (list (string-append + "XDG_RUNTIME_DIR=/run/user/" + (number->string + (passwd:uid + (getpwnam #$(mpd-configuration-user config)))))) + #:log-file #$(mpd-file-name config "log")))) + (stop (if (mpd-configuration-shepherd-endpoints config) + #~(make-systemd-destructor) + #~(make-kill-destructor))))) (define (mpd-service-activation config) (with-imported-modules '((guix build utils)) -- 2.37.3