aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/audio.scm
blob: 345d8225b23bf8a0efe2f2a5e18d658ef641dc0b (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Peter Mikkelsen <petermikkelsen10@gmail.com>
;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services audio)
  #:use-module (guix gexp)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu packages mpd)
  #:use-module (guix records)
  #:use-module (ice-9 match)
  #:export (mpd-output
            mpd-output?
            mpd-configuration
            mpd-configuration?
            mpd-service-type))

;;; Commentary:
;;;
;;; Audio related services
;;;
;;; Code:

(define-record-type* <mpd-output>
  mpd-output make-mpd-output
  mpd-output?
  (type          mpd-output-type
                 (default "pulse"))
  (name          mpd-output-name
                 (default "MPD"))
  (enabled?      mpd-output-enabled?
                 (default #t))
  (tags?         mpd-output-tags?
                 (default #t))
  (always-on?    mpd-output-always-on?
                 (default #f))
  (mixer-type    mpd-output-mixer-type
                 ;; valid: hardware, software, null, none
                 (default #f))
  (extra-options mpd-output-extra-options
                 (default '())))

(define-record-type* <mpd-configuration>
  mpd-configuration make-mpd-configuration
  mpd-configuration?
  (user         mpd-configuration-user
                (default "mpd"))
  (music-dir    mpd-configuration-music-dir
                (default "~/Music"))
  (playlist-dir mpd-configuration-playlist-dir
                (default "~/.mpd/playlists"))
  (db-file      mpd-configuration-db-file
                (default "~/.mpd/tag_cache"))
  (state-file   mpd-configuration-state-file
                (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"))
  (outputs      mpd-configuration-outputs
                (default (list (mpd-output)))))

(define (mpd-output->string output)
  "Convert the OUTPUT of type <mpd-output> to a configuration file snippet."
  (let ((extra (string-join
                (map (match-lambda
                       ((key . value)
                        (format #f "  ~a \"~a\""
                                (string-map
                                 (lambda (c) (if (char=? c #\-) #\_ c))
                                 (symbol->string key))
                                value)))
                     (mpd-output-extra-options output))
                "\n")))
    (format #f "\
audio_output {
  type \"~a\"
  name \"~a\"
~:[  enabled \"no\"~%~;~]\
~:[  tags \"no\"~%~;~]\
~:[~;  always_on \"yes\"~%~]\
~@[  mixer_type \"~a\"~%~]\
~a~%}~%"
            (mpd-output-type output)
            (mpd-output-name output)
            (mpd-output-enabled? output)
            (mpd-output-tags? output)
            (mpd-output-always-on? output)
            (mpd-output-mixer-type output)
            extra)))

(define (mpd-config->file config)
  (apply
   mixed-text-file "mpd.conf"
   "pid_file \"" (mpd-file-name config "pid") "\"\n"
   (append (map mpd-output->string
                (mpd-configuration-outputs config))
           (map (match-lambda
                  ((config-name config-val)
                   (string-append config-name " \"" (config-val config) "\"\n")))
                `(("user" ,mpd-configuration-user)
                  ("music_directory" ,mpd-configuration-music-dir)
                  ("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))))))

(define (mpd-file-name config file)
  "Return a path in /var/run/mpd/ that is writable
   by @code{user} from @code{config}."
  (string-append "/var/run/mpd/"
                 (mpd-configuration-user config)
                 "/" file))

(define (mpd-shepherd-service config)
  (shepherd-service
   (documentation "Run the MPD (Music Player Daemon)")
   (provision '(mpd))
   (start #~(make-forkexec-constructor
             (list #$(file-append mpd "/bin/mpd")
                   "--no-daemon"
                   #$(mpd-config->file config))
             #:pid-file #$(mpd-file-name config "pid")
             #:environment-variables
             ;; Required to detect PulseAudio when run under a user account.
             '(#$(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))))

(define (mpd-service-activation config)
  (with-imported-modules '((guix build utils))
    #~(begin
        (use-modules (guix build utils))
        (define %user
          (getpw #$(mpd-configuration-user config)))

        (let ((directory #$(mpd-file-name config "")))
          (mkdir-p directory)
          (chown directory (passwd:uid %user) (passwd:gid %user))))))

(define mpd-service-type
  (service-type
   (name 'mpd)
   (description "Run the Music Player Daemon (MPD).")
   (extensions
    (list (service-extension shepherd-root-service-type
                             (compose list mpd-shepherd-service))
          (service-extension activation-service-type
                             mpd-service-activation)))
   (default-value (mpd-configuration))))
dd guix/build/pyproject-build-system.scm and guix/build-system/pyproject.scm to python team's scope. Signed-off-by: Christopher Baines <mail@cbaines.net> jgart 2022-11-05news: Add 'pt' translation....* etc/news.scm: Add Portuguese translation of entry about pyproject-build-system. Signed-off-by: Florian Pelz <pelzflorian@pelzflorian.de> Thiago Jung Bauermann 2022-11-03etc: teams: Add help information for commands....* etc/teams.scm.in (main): Add command information to usage help prompt. Signed-off-by: Christopher Baines <mail@cbaines.net> Antero Mejr 2022-10-23etc: systemd services shouldn't ‘RemainAfterExit’....* etc/guix-daemon.service.in (RemainAfterExit): Don't. * etc/guix-publish.service.in (RemainAfterExit): Likewise don't. Tobias Geerinckx-Rice 2022-10-23etc: Add ‘Restart=always’ to both systemd services....* etc/guix-daemon.service.in (Restart): ‘Always’ do. * etc/guix-publish.service.in (Restart): Likewise. Tobias Geerinckx-Rice 2022-10-23etc: Add ‘OOMPolicy=continue’ to guix-daemon.service....* etc/guix-daemon.service.in (OOMPolicy): Continue. Tobias Geerinckx-Rice 2022-10-27news: Add entry for 'pyproject-build-system'....* etc/news.scm: Add entry. Co-authored-by: Florian Pelz <pelzflorian@pelzflorian.de> Co-authored-by: Julien Lepiller <julien@lepiller.eu> Marius Bakke 2022-10-25maint: Tweak release manifest special case for armhf-linux....Don't remove the emacs package, as it does build and substitutes are available. Do remove the guix package though, as it doesn't build due to Guile memory issues while compiling the package modules. * etc/release-manifest.scm (%base-packages/armhf): Don't replace the emacs package, remove the guix package. (%base-manifest): Remove FIXME comment as %base-packages/armhf doesn't relate to build power. Christopher Baines 2022-10-22snippets: Harden for review activity....When reviewing patches, whose commit logs don't follow the structure outlined in “Submitting Patches”, a reviewer might be tempted to use snippets to rewrite them. This makes it so that their attempt, while not immediately succeeding, isn't completely thwarted. * etc/snippets/tempel/text-mode (add\ , remove\ , rename\ , update\ ) (addcl\ , https\ ): Use an empty "p" field if (car (magit-staged-files)) fails. Liliana Marie Prikler 2022-10-16guix-install.sh: Cosmetically tweak non-interactive output....Avoid printing Press return to continue...[1666352494.051]: Starting installation… [1666352648.869]: … when the return itself wasn't echoed on the console. * etc/guix-install.sh (welcome): Add a carriage return to the prompt, so that the next line of output may overwrite it. Tobias Geerinckx-Rice 2022-10-16guix-install.sh: Warn if we suspect dodgy automation....This doesn't affect the installation (yet), but reserves the right to default to safe values other than ‘y’ in future. * etc/guix-install.sh (welcome): Warn if the ‘return’ wasn't. Tobias Geerinckx-Rice 2022-10-16guix-install.sh: Treat all uncaught errors as fatal....* etc/guix-install.sh: Set -o pipefail. Tobias Geerinckx-Rice 2022-10-16guix-install.sh: Suggest what to do if fetching OpenPGP key(s) fails....* etc/guix-install.sh (chk_gpg_keyring): Report an _err and set the exit_flag if wget | gpg --import fails. Tobias Geerinckx-Rice 2022-10-16guix-install.sh: Time out fetching OpenPGP keys....The default 900s provide no useful backstop in interactive use. * etc/guix-install.sh (chk_gpg_keyring): Add a 30s wget --timeout. Tobias Geerinckx-Rice 2022-10-17news: Add 'pt' translation....* etc/news.scm: Add Portuguese translation of entry about the new --emulate-fhs option. Signed-off-by: Julien Lepiller <julien@lepiller.eu> Thiago Jung Bauermann 2022-10-14news: Add 'de' translation....* etc/news.scm: Add German translation of '--emulate-fhs' entry. Florian Pelz 2022-10-13news: Add entry for 'guix shell --emulate-fhs'....* etc/news.scm: Add entry. Ludovic Courtès 2022-10-11guix-install.sh: Restore compatibility with "yes" invocation....Commit 6a2e303d3a had modified prompt_yes_no to only read a single character, aiming to ease the user experience. This was, in retrospect, a bad idea, as it makes user input error more likely and introduces complexity. This commit reverts to line-oriented input, while preserving the default yes value so that a user can simply hit 'Enter' at the prompt in place of typing "yes". * etc/guix-install.sh (_flush): Delete function. (prompt_yes_no): Restore line-oriented read. Remove loop. Make anything else than yes means no. Use Bash features to streamline definition. Reported-by: Lars-Dominik Braun <lars@6xq.net> and others. Maxim Cournoyer 2022-10-07guix-install.sh: Add Bash prompt customization option....Fixes <https://issues.guix.gnu.org/55484>. * etc/guix-install.sh (sys_customize_bashrc): New function. (main): Use it. Maxim Cournoyer 2022-10-07guix-install.sh: Introduce 'die' utility function....* etc/guix-install.sh (die): New function. (chk_sys_arch): Use it. (guix_get_bin_list, guix_get_bin, sys_create_store): Likewise. Maxim Cournoyer