From patchwork Sat Apr 23 14:39:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liliana Marie Prikler X-Patchwork-Id: 42452 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 C733E27BBE9; Sat, 10 Sep 2022 19:32:14 +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.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, 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 B3D3A27BBEA for ; Sat, 10 Sep 2022 19:32:13 +0100 (BST) Received: from localhost ([::1]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oX5H2-0007gV-S1 for patchwork@mira.cbaines.net; Sat, 10 Sep 2022 14:32:12 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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))