aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/mpd.scm
blob: e8b1e6e0b1c077ee31b8e555b5fa0c60fd8d37cf (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 David Thompson <dthompson2@worcester.edu>
;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
;;; Copyright © 2015 Paul van der Walt <paul@denknerd.org>
;;; Copyright © 2016, 2018, 2019 Leo Famulari <leo@famulari.name>
;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;;
;;; 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 packages mpd)
  #:use-module (gnu packages)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system meson)
  #:use-module (guix build-system python)
  #:use-module (gnu packages avahi)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages documentation)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages mp3)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages sphinx)
  #:use-module (gnu packages sqlite)
  #:use-module (gnu packages video)
  #:use-module (gnu packages xiph))

(define-public libmpdclient
  (package
    (name "libmpdclient")
    (version "2.16")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://musicpd.org/download/libmpdclient/"
                              (car (string-split version #\.))
                              "/libmpdclient-" version ".tar.xz"))
              (sha256
               (base32
                "0r24cl3i9nvs6a47mvwaxk1kb5wmnhkhrw1q5cq9010fgjvdlszs"))))
    (build-system meson-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)

       ;; For building HTML documentation.
       ("doxygen" ,doxygen)

       ;; For tests.
       ("check" ,check)))
    (arguments
     `(#:configure-flags
       (list "-Ddocumentation=true"
             "-Dtest=true")))
    (synopsis "Music Player Daemon client library")
    (description "A stable, documented, asynchronous API library for
interfacing MPD in the C, C++ & Objective C languages.")
    (home-page "https://www.musicpd.org/libs/libmpdclient/")
    (license license:bsd-3)))

(define-public mpd
  (package
    (name "mpd")
    (version "0.21.14")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://musicpd.org/download/mpd/"
                              (version-major+minor version)
                              "/mpd-" version ".tar.xz"))
              (sha256
               (base32
                "0iknnm9xvwfgk8h82hjwrmbijpk9l0dgap0794c2nyg8i66qlb0y"))))
    (build-system meson-build-system)
    (arguments
     `(#:configure-flags '("-Ddocumentation=true") ; the default is 'false'...
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'expand-C++-include-path
           ;; Make <gcc>/include/c++/ext/string_conversions.h find <stdlib.h>.
           (lambda* (#:key inputs #:allow-other-keys)
             (let* ((path "CPLUS_INCLUDE_PATH")
                    (gcc  (assoc-ref inputs "gcc"))
                    (c++  (string-append gcc "/include/c++")))
               (setenv path (string-append c++ ":" (getenv path)))
               #t))))))
    (inputs `(("ao" ,ao)
              ("alsa-lib" ,alsa-lib)
              ("avahi" ,avahi)
              ("boost" ,boost)
              ("curl" ,curl)
              ("ffmpeg" ,ffmpeg)
              ("flac" ,flac)
              ("glib" ,glib)
              ("icu4c" ,icu4c)
              ;; The LAME decoder comes from FFmpeg, but is added here so that
              ;; configure picks up the LAME encoder.
              ("lame" ,lame)
              ("libid3tag" ,libid3tag)
              ("libmpdclient" ,libmpdclient)
              ("libsamplerate" ,libsamplerate)
              ("libsndfile" ,libsndfile)
              ("libvorbis" ,libvorbis)
              ("opus" ,opus)
              ("pulseaudio" ,pulseaudio)
              ("sqlite" ,sqlite)
              ("zlib" ,zlib)))
    ;; MPD > 0.21 requires > GCC 6
    (native-inputs `(("gcc" ,gcc-8)
                     ("gcc-lib" ,gcc-8 "lib")
                     ("pkg-config" ,pkg-config)
                     ("python-sphinx" ,python-sphinx)))
    ;; Missing optional inputs:
    ;;   libyajl
    ;;   libcdio_paranoia
    ;;   libmms
    ;;   libadplug
    ;;   libaudiofile
    ;;   faad2
    ;;   fluidsynth
    ;;   libgme
    ;;   libshout
    ;;   libmpg123
    ;;   libmodplug
    ;;   libmpcdec
    ;;   libsidplay2
    ;;   libwavpack
    ;;   libwildmidi
    ;;   libtwolame
    ;;   libroar
    ;;   libjack
    ;;   OpenAL
    (synopsis "Music Player Daemon")
    (description "Music Player Daemon (MPD) is a flexible, powerful,
server-side application for playing music.  Through plugins and libraries it
can play a variety of sound files while being controlled by its network
protocol.")
    (home-page "https://www.musicpd.org/")
    (license license:gpl2)))

(define-public mpd-mpc
  (package
    (name "mpd-mpc")
    (version "0.32")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://www.musicpd.org/download/mpc/"
                              (car (string-split version #\.))
                              "/mpc-" version ".tar.xz"))
              (sha256
               (base32
                "1irilgz64pny7b8zygy5i74nfmlhgsawz0djx9mrj6g0gidxjqbr"))))
    (build-system meson-build-system)
    (inputs `(("libmpdclient" ,libmpdclient)))
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("python-sphinx" ,python-sphinx)))
    (synopsis "Music Player Daemon client")
    (description "MPC is a minimalist command line interface to MPD, the music
player daemon.")
    (home-page "https://www.musicpd.org/clients/mpc/")
    (license license:gpl2)))

(define-public ncmpc
  (package
    (name "ncmpc")
    (version "0.34")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "http://musicpd.org/download/ncmpc/"
                              (version-major version)
                              "/ncmpc-" version ".tar.xz"))
              (sha256
               (base32
                "0mz8r6vc4zn5sa3hlq4ii74qcrkh01nbg784zcwahgz8g3fb3i8l"))))
    (build-system meson-build-system)
    (arguments
     `(#:configure-flags
       ;; Otherwise, they are installed incorrectly, in
       ;; '$out/share/man/man/man1'.
       (list (string-append "-Dmandir=" (assoc-ref %outputs "out")
                            "/share"))
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'expand-C++-include-path
           ;; Make <gcc>/include/c++/ext/string_conversions.h find <stdlib.h>.
           (lambda* (#:key inputs #:allow-other-keys)
             (let* ((path "CPLUS_INCLUDE_PATH")
                    (gcc  (assoc-ref inputs "gcc"))
                    (c++  (string-append gcc "/include/c++")))
               (setenv path (string-append c++ ":" (getenv path)))
               #t))))))
    (inputs `(("gcc" ,gcc-8)            ; for its C++14 support
              ("boost" ,boost)
              ("pcre" ,pcre)
              ("libmpdclient" ,libmpdclient)
              ("ncurses" ,ncurses)))
    (native-inputs `(("gettext" ,gettext-minimal) ; for xgettext
                     ("pkg-config" ,pkg-config)
                     ("python-sphinx" ,python-sphinx)))
    (synopsis "Curses Music Player Daemon client")
    (description "ncmpc is a fully featured MPD client, which runs in a
terminal using ncurses.")
    (home-page "https://www.musicpd.org/clients/ncmpc/")
    (license license:gpl2)))

(define-public ncmpcpp
  (package
    (name "ncmpcpp")
    (version "0.8.2")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://ncmpcpp.rybczak.net/stable/ncmpcpp-"
                              version ".tar.bz2"))
              (sha256
               (base32
                "0m0mjb049sl62vx13h9waavysa30mk0rphacksnvf94n13la62v5"))))
    (build-system gnu-build-system)
    (inputs `(("libmpdclient" ,libmpdclient)
              ("boost"  ,boost)
              ("readline" ,readline)
              ("ncurses" ,ncurses)
              ("taglib" ,taglib)
              ("icu4c" ,icu4c)
              ("curl" ,curl)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (arguments
     '(#:configure-flags
       '("BOOST_LIB_SUFFIX=" "--with-taglib")))
    (synopsis "Featureful ncurses based MPD client inspired by ncmpc")
    (description "Ncmpcpp is an mpd client with a UI very similar to ncmpc,
but it provides new useful features such as support for regular expressions
for library searches, extended song format, items filtering, the ability to
sort playlists, and a local file system browser.")
    (home-page "https://ncmpcpp.rybczak.net/")
    (license license:gpl2+)))

(define-public mpdscribble
  (package
    (name "mpdscribble")
    (version "0.22")
    (source (origin
              (method url-fetch)
              (uri (string-append "http://www.musicpd.org/download/mpdscribble/"
                                  version "/mpdscribble-" version ".tar.gz"))
              (sha256
               (base32
                "0f0ybx380x2z2g1qvdndpvcrhkrgsfqckhz3ryydq2w3pl12v27z"))))
    (build-system gnu-build-system)
    (inputs `(("libmpdclient" ,libmpdclient)
              ("curl" ,curl)
              ("glib" ,glib)))
    (native-inputs `(("pkg-config" ,pkg-config)))
    (synopsis "MPD client for track scrobbling")
    (description "mpdscribble is a Music Player Daemon client which submits
information about tracks being played to a scrobbler, such as Libre.FM.")
    (home-page "https://www.musicpd.org/clients/mpdscribble/")
    (license license:gpl2+)))

(define-public python-mpd2
  (package
    (name "python-mpd2")
    (version "0.5.5")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "python-mpd2" version))
              (sha256
               (base32
                "0laypd7h1j14b4vrmiayqlzdsh2j5hc3zv4l0fqvbrbw9y6763ii"))))
    (build-system python-build-system)
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda _ (invoke "python" "mpd_test.py"))))))
    (native-inputs `(("python-mock" ,python-mock)))
    (home-page "https://github.com/Mic92/python-mpd2")
    (synopsis "Python MPD client library")
    (description "Python-mpd2 is a Python library which provides a client
interface for the Music Player Daemon.")
    (license license:lgpl3+)))

(define-public python2-mpd2
  (package-with-python2 python-mpd2))

(define-public sonata
  (package
    (name "sonata")
    (version "1.7b1")
    (source (origin
              (method url-fetch)
              (uri
               (string-append "https://github.com/multani/sonata/archive/v"
                              version ".tar.gz"))
              (file-name (string-append name "-" version ".tar.gz"))
              (sha256
               (base32
                "07gq2nxqwxs0qyxjbay7k5j25zd386bn7wdr2dl1gk53diwnn7s0"))))
    (build-system python-build-system)
    (arguments
     `(#:modules ((guix build gnu-build-system)
                  (guix build python-build-system)
                  ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
                  (guix build utils))
       #:imported-modules (,@%gnu-build-system-modules
                           (guix build python-build-system)
                           (guix build glib-or-gtk-build-system))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'glib-or-gtk-wrap
           (assoc-ref glib-or-gtk:%standard-phases 'glib-or-gtk-wrap))
         (add-after 'install 'wrap-sonata
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out               (assoc-ref outputs "out"))
                   (gi-typelib-path   (getenv "GI_TYPELIB_PATH")))
               (wrap-program (string-append out "/bin/sonata")
                 `("GI_TYPELIB_PATH" ":" prefix (,gi-typelib-path))))
             #t)))))
    (native-inputs
     `(("gettext" ,gettext-minimal)))
    (inputs
     `(("python-mpd2" ,python-mpd2)
       ("gtk+" ,gtk+)
       ("gsettings-desktop-schemas" ,gsettings-desktop-schemas)
       ("gobject-introspection" ,gobject-introspection)
       ("adwaita-icon-theme" ,adwaita-icon-theme)
       ("python-pygobject" ,python-pygobject)))
    (synopsis "Elegant client for the Music Player Daemon")
    (description "Sonata is an elegant graphical client for the Music Player
Daemon (MPD).  It supports playlists, multiple profiles (connecting to different
MPD servers, search and multimedia key support.")
    (home-page "https://www.nongnu.org/sonata/")
    (license license:gpl3+)))
ident_file" ,@(single-quote ident-file)) ,@extra-config))) (gexp->derivation "postgresql.conf" #~(call-with-output-file (ungexp output "out") (lambda (port) (display (string-append #$@contents) port))) #:local-build? #t)))) (define-record-type* <postgresql-configuration> postgresql-configuration make-postgresql-configuration postgresql-configuration? (postgresql postgresql-configuration-postgresql ;<package> (default postgresql)) (port postgresql-configuration-port (default 5432)) (locale postgresql-configuration-locale (default "en_US.utf8")) (config-file postgresql-configuration-file (default (postgresql-config-file))) (data-directory postgresql-configuration-data-directory (default "/var/lib/postgresql/data")) (extension-packages postgresql-configuration-extension-packages (default '()))) (define %postgresql-accounts (list (user-group (name "postgres") (system? #t)) (user-account (name "postgres") (group "postgres") (system? #t) (comment "PostgreSQL server user") (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define (final-postgresql postgresql extension-packages) (if (null? extension-packages) postgresql (package (inherit postgresql) (source #f) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils) (guix build union)) #:builder (begin (use-modules (guix build utils) (guix build union) (srfi srfi-26)) (union-build (assoc-ref %outputs "out") (map (lambda (input) (cdr input)) %build-inputs)) #t))) (inputs `(("postgresql" ,postgresql) ,@(map (lambda (extension) (list "extension" extension)) extension-packages)))))) (define postgresql-activation (match-lambda (($ <postgresql-configuration> postgresql port locale config-file data-directory extension-packages) #~(begin (use-modules (guix build utils) (ice-9 match)) (let ((user (getpwnam "postgres")) (initdb (string-append #$(final-postgresql postgresql extension-packages) "/bin/initdb")) (initdb-args (append (if #$locale (list (string-append "--locale=" #$locale)) '())))) ;; Create db state directory. (mkdir-p #$data-directory) (chown #$data-directory (passwd:uid user) (passwd:gid user)) ;; Drop privileges and init state directory in a new ;; process. Wait for it to finish before proceeding. (match (primitive-fork) (0 ;; Exit with a non-zero status code if an exception is thrown. (dynamic-wind (const #t) (lambda () (setgid (passwd:gid user)) (setuid (passwd:uid user)) (primitive-exit (apply system* initdb "-D" #$data-directory initdb-args))) (lambda () (primitive-exit 1)))) (pid (waitpid pid)))))))) (define postgresql-shepherd-service (match-lambda (($ <postgresql-configuration> postgresql port locale config-file data-directory extension-packages) (let* ((pg_ctl-wrapper ;; Wrapper script that switches to the 'postgres' user before ;; launching daemon. (program-file "pg_ctl-wrapper" #~(begin (use-modules (ice-9 match) (ice-9 format)) (match (command-line) ((_ mode) (let ((user (getpwnam "postgres")) (pg_ctl #$(file-append (final-postgresql postgresql extension-packages) "/bin/pg_ctl")) (options (format #f "--config-file=~a -p ~d" #$config-file #$port))) (setgid (passwd:gid user)) (setuid (passwd:uid user)) (execl pg_ctl pg_ctl "-D" #$data-directory "-o" options mode))))))) (pid-file (in-vicinity data-directory "postmaster.pid")) (action (lambda args #~(lambda _ (invoke #$pg_ctl-wrapper #$@args) (match '#$args (("start") (call-with-input-file #$pid-file read)) (_ #t)))))) (list (shepherd-service (provision '(postgres)) (documentation "Run the PostgreSQL daemon.") (requirement '(user-processes loopback syslogd)) (modules `((ice-9 match) ,@%default-modules)) (start (action "start")) (stop (action "stop")))))))) (define postgresql-service-type (service-type (name 'postgresql) (extensions (list (service-extension shepherd-root-service-type postgresql-shepherd-service) (service-extension activation-service-type postgresql-activation) (service-extension account-service-type (const %postgresql-accounts)) (service-extension profile-service-type (compose list postgresql-configuration-postgresql)))) (default-value (postgresql-configuration)))) (define* (postgresql-service #:key (postgresql postgresql) (port 5432) (locale "en_US.utf8") (config-file (postgresql-config-file)) (data-directory "/var/lib/postgresql/data") (extension-packages '())) "Return a service that runs @var{postgresql}, the PostgreSQL database server. The PostgreSQL daemon loads its runtime configuration from @var{config-file} and stores the database cluster in @var{data-directory}." (service postgresql-service-type (postgresql-configuration (postgresql postgresql) (port port) (locale locale) (config-file config-file) (data-directory data-directory) (extension-packages extension-packages)))) ;;; ;;; Memcached ;;; (define-record-type* <memcached-configuration> memcached-configuration make-memcached-configuration memcached-configuration? (memcached memcached-configuration-memcached ;<package> (default memcached)) (interfaces memcached-configuration-interfaces (default '("0.0.0.0"))) (tcp-port memcached-configuration-tcp-port (default 11211)) (udp-port memcached-configuration-udp-port (default 11211)) (additional-options memcached-configuration-additional-options (default '()))) (define %memcached-accounts (list (user-group (name "memcached") (system? #t)) (user-account (name "memcached") (group "memcached") (system? #t) (comment "Memcached server user") (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define memcached-activation #~(begin (use-modules (guix build utils)) (let ((user (getpwnam "memcached"))) (mkdir-p "/var/run/memcached") (chown "/var/run/memcached" (passwd:uid user) (passwd:gid user))))) (define memcached-shepherd-service (match-lambda (($ <memcached-configuration> memcached interfaces tcp-port udp-port additional-options) (with-imported-modules (source-module-closure '((gnu build shepherd))) (list (shepherd-service (provision '(memcached)) (documentation "Run the Memcached daemon.") (requirement '(user-processes loopback)) (modules '((gnu build shepherd))) (start #~(make-forkexec-constructor `(#$(file-append memcached "/bin/memcached") "-l" #$(string-join interfaces ",") "-p" #$(number->string tcp-port) "-U" #$(number->string udp-port) "--daemon" ;; Memcached changes to the memcached user prior to ;; writing the pid file, so write it to a directory ;; that memcached owns. "-P" "/var/run/memcached/pid" "-u" "memcached" ,#$@additional-options) #:log-file "/var/log/memcached" #:pid-file "/var/run/memcached/pid")) (stop #~(make-kill-destructor)))))))) (define memcached-service-type (service-type (name 'memcached) (extensions (list (service-extension shepherd-root-service-type memcached-shepherd-service) (service-extension activation-service-type (const memcached-activation)) (service-extension account-service-type (const %memcached-accounts)))) (default-value (memcached-configuration)))) ;;; ;;; MongoDB ;;; (define %default-mongodb-configuration-file (plain-file "mongodb.yaml" "# GNU Guix: MongoDB default configuration file processManagement: pidFilePath: /var/run/mongodb/pid storage: dbPath: /var/lib/mongodb ")) (define-record-type* <mongodb-configuration> mongodb-configuration make-mongodb-configuration mongodb-configuration? (mongodb mongodb-configuration-mongodb (default mongodb)) (config-file mongodb-configuration-config-file (default %default-mongodb-configuration-file)) (data-directory mongodb-configuration-data-directory (default "/var/lib/mongodb"))) (define %mongodb-accounts (list (user-group (name "mongodb") (system? #t)) (user-account (name "mongodb") (group "mongodb") (system? #t) (comment "Mongodb server user") (home-directory "/var/lib/mongodb") (shell (file-append shadow "/sbin/nologin"))))) (define mongodb-activation (match-lambda (($ <mongodb-configuration> mongodb config-file data-directory) #~(begin (use-modules (guix build utils)) (let ((user (getpwnam "mongodb"))) (for-each (lambda (directory) (mkdir-p directory) (chown directory (passwd:uid user) (passwd:gid user))) '("/var/run/mongodb" #$data-directory))))))) (define mongodb-shepherd-service (match-lambda (($ <mongodb-configuration> mongodb config-file data-directory) (shepherd-service (provision '(mongodb)) (documentation "Run the Mongodb daemon.") (requirement '(user-processes loopback)) (start #~(make-forkexec-constructor `(,(string-append #$mongodb "/bin/mongod") "--config" ,#$config-file) #:user "mongodb" #:group "mongodb" #:pid-file "/var/run/mongodb/pid" #:log-file "/var/log/mongodb.log")) (stop #~(make-kill-destructor)))))) (define mongodb-service-type (service-type (name 'mongodb) (description "Run the MongoDB document database server.") (extensions (list (service-extension shepherd-root-service-type (compose list mongodb-shepherd-service)) (service-extension activation-service-type mongodb-activation) (service-extension account-service-type (const %mongodb-accounts)))) (default-value (mongodb-configuration)))) ;;; ;;; MySQL. ;;; (define-record-type* <mysql-configuration> mysql-configuration make-mysql-configuration mysql-configuration? (mysql mysql-configuration-mysql (default mariadb)) (port mysql-configuration-port (default 3306)) (extra-content mysql-configuration-extra-content (default ""))) (define %mysql-accounts (list (user-group (name "mysql") (system? #t)) (user-account (name "mysql") (group "mysql") (system? #t) (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define mysql-configuration-file (match-lambda (($ <mysql-configuration> mysql port extra-content) (mixed-text-file "my.cnf" "[mysqld] datadir=/var/lib/mysql socket=/run/mysqld/mysqld.sock port=" (number->string port) " " extra-content " ")))) (define (%mysql-activation config) "Return an activation gexp for the MySQL or MariaDB database server." (let ((mysql (mysql-configuration-mysql config)) (my.cnf (mysql-configuration-file config))) #~(begin (use-modules (ice-9 popen) (guix build utils)) (let* ((mysqld (string-append #$mysql "/bin/mysqld")) (user (getpwnam "mysql")) (uid (passwd:uid user)) (gid (passwd:gid user)) (datadir "/var/lib/mysql") (rundir "/run/mysqld")) (mkdir-p datadir) (chown datadir uid gid) (mkdir-p rundir) (chown rundir uid gid) ;; Initialize the database when it doesn't exist. (when (not (file-exists? (string-append datadir "/mysql"))) (if (string-prefix? "mysql-" (strip-store-file-name #$mysql)) ;; For MySQL. (system* mysqld (string-append "--defaults-file=" #$my.cnf) "--initialize" "--user=mysql") ;; For MariaDB. ;; XXX: The 'mysql_install_db' script doesn't work directly ;; due to missing 'mkdir' in PATH. (let ((p (open-pipe* OPEN_WRITE mysqld (string-append "--defaults-file=" #$my.cnf) "--bootstrap" "--user=mysql"))) ;; Create the system database, as does by 'mysql_install_db'. (display "create database mysql;\n" p) (display "use mysql;\n" p) (for-each (lambda (sql) (call-with-input-file (string-append #$mysql:lib "/share/mysql/" sql) (lambda (in) (dump-port in p)))) '("mysql_system_tables.sql" "mysql_performance_tables.sql" "mysql_system_tables_data.sql" "fill_help_tables.sql")) ;; Remove the anonymous user and disable root access from ;; remote machines, as does by 'mysql_secure_installation'. (display " DELETE FROM user WHERE User=''; DELETE FROM user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); FLUSH PRIVILEGES; " p) (close-pipe p)))))))) (define (mysql-shepherd-service config) (list (shepherd-service (provision '(mysql)) (documentation "Run the MySQL server.") (start (let ((mysql (mysql-configuration-mysql config)) (my.cnf (mysql-configuration-file config))) #~(make-forkexec-constructor (list (string-append #$mysql "/bin/mysqld") (string-append "--defaults-file=" #$my.cnf)) #:user "mysql" #:group "mysql"))) (stop #~(make-kill-destructor))))) (define mysql-service-type (service-type (name 'mysql) (extensions (list (service-extension account-service-type (const %mysql-accounts)) (service-extension activation-service-type %mysql-activation) (service-extension shepherd-root-service-type mysql-shepherd-service))) (default-value (mysql-configuration)))) (define* (mysql-service #:key (config (mysql-configuration))) "Return a service that runs @command{mysqld}, the MySQL or MariaDB database server. The optional @var{config} argument specifies the configuration for @command{mysqld}, which should be a @code{<mysql-configuration>} object." (service mysql-service-type config)) ;;; ;;; Redis ;;; (define-record-type* <redis-configuration> redis-configuration make-redis-configuration redis-configuration? (redis redis-configuration-redis ;<package> (default redis)) (bind redis-configuration-bind (default "127.0.0.1")) (port redis-configuration-port (default 6379)) (working-directory redis-configuration-working-directory (default "/var/lib/redis")) (config-file redis-configuration-config-file (default #f))) (define (default-redis.conf bind port working-directory) (mixed-text-file "redis.conf" "bind " bind "\n" "port " (number->string port) "\n" "dir " working-directory "\n" "daemonize no\n")) (define %redis-accounts (list (user-group (name "redis") (system? #t)) (user-account (name "redis") (group "redis") (system? #t) (comment "Redis server user") (home-directory "/var/empty") (shell (file-append shadow "/sbin/nologin"))))) (define redis-activation (match-lambda (($ <redis-configuration> redis bind port working-directory config-file) #~(begin (use-modules (guix build utils) (ice-9 match)) (let ((user (getpwnam "redis"))) (mkdir-p #$working-directory) (chown #$working-directory (passwd:uid user) (passwd:gid user))))))) (define redis-shepherd-service (match-lambda (($ <redis-configuration> redis bind port working-directory config-file) (let ((config-file (or config-file (default-redis.conf bind port working-directory)))) (list (shepherd-service (provision '(redis)) (documentation "Run the Redis daemon.") (requirement '(user-processes syslogd)) (start #~(make-forkexec-constructor '(#$(file-append redis "/bin/redis-server") #$config-file) #:user "redis" #:group "redis")) (stop #~(make-kill-destructor)))))))) (define redis-service-type (service-type (name 'redis) (extensions (list (service-extension shepherd-root-service-type redis-shepherd-service) (service-extension activation-service-type redis-activation) (service-extension account-service-type (const %redis-accounts)))) (default-value (redis-configuration))))