2022-11-08 05:16:19 +01:00
|
|
|
(define-module (oni home services mpd)
|
|
|
|
#:use-module (gnu services configuration)
|
|
|
|
#:use-module (gnu packages mpd)
|
|
|
|
#:use-module (gnu home services)
|
|
|
|
#:use-module (gnu home services shepherd)
|
|
|
|
#:use-module (gnu home services utils)
|
|
|
|
#:use-module (guix packages)
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (oop goops)
|
|
|
|
#:use-module (ice-9 string-fun)
|
2023-03-08 08:51:42 +01:00
|
|
|
#:use-module ((oni packages mpd-notify)
|
|
|
|
#:select (mpd-notify))
|
2022-11-08 05:16:19 +01:00
|
|
|
|
|
|
|
#:export (home-mpd-service-type
|
|
|
|
home-mpd-configuration
|
2022-11-08 06:46:07 +01:00
|
|
|
<home-mpd-audio-output>
|
|
|
|
|
|
|
|
home-mpc-update-service-type
|
2023-03-08 08:51:42 +01:00
|
|
|
home-mpc-update-configuration
|
|
|
|
|
|
|
|
home-mpd-notify-service-type
|
|
|
|
home-mpd-notify-configuration))
|
2022-11-08 05:16:19 +01:00
|
|
|
|
|
|
|
(define (serialize-boolean field value)
|
|
|
|
"")
|
|
|
|
|
|
|
|
(define (serialize-home-mpd-audio-output config)
|
|
|
|
(let ((type (slot-ref config 'type))
|
|
|
|
(name (slot-ref config 'name))
|
|
|
|
(path (slot-ref config 'path))
|
|
|
|
(fmt (slot-ref config 'format)))
|
|
|
|
(list "audio_output {"
|
|
|
|
(format #f " type ~s" type)
|
|
|
|
(format #f " name ~s" name)
|
|
|
|
(if path (format #f " path ~s" path) "")
|
|
|
|
(if fmt (format #f " format ~s" fmt) "")
|
|
|
|
"}")))
|
|
|
|
|
|
|
|
(define (serialize-home-mpd-audio-output-list field value)
|
|
|
|
(string-join
|
|
|
|
(apply append (map serialize-home-mpd-audio-output value))
|
|
|
|
"\n"))
|
|
|
|
|
|
|
|
(define (serialize-string field value)
|
|
|
|
(format #f "~a ~s\n" (string-replace-substring (symbol->string field) "-" "_") value))
|
|
|
|
|
|
|
|
(define (type? value)
|
|
|
|
(member value '("shout" "null" "fifo" "pipe" "alsa" "ao" "oss" "openal"
|
|
|
|
"solaris" "pipewire" "pulse" "jack" "httpd" "snapcast"
|
|
|
|
"recorder")))
|
|
|
|
|
|
|
|
(define (home-mpd-audio-output-list? value)
|
|
|
|
(and (list? value)
|
2023-06-21 08:06:25 +02:00
|
|
|
(every (λ (v) (is-a? v <home-mpd-audio-output>)) value)))
|
2022-11-08 05:16:19 +01:00
|
|
|
|
|
|
|
(define-maybe string)
|
|
|
|
(define-maybe home-mpd-audio-output-list)
|
|
|
|
|
|
|
|
(define-configuration home-mpd-configuration
|
|
|
|
(package
|
|
|
|
(package mpd)
|
|
|
|
"Package to use for settings MPD")
|
|
|
|
(auto-start?
|
|
|
|
(boolean #t)
|
|
|
|
"Should MPD be started automatically")
|
|
|
|
(db-file
|
|
|
|
maybe-string
|
|
|
|
"Where the db file will be stored")
|
|
|
|
(log-file
|
|
|
|
maybe-string
|
|
|
|
"Where the log file should be located")
|
|
|
|
(pid-file
|
|
|
|
maybe-string
|
|
|
|
"The file to save mpd's process ID in")
|
|
|
|
(music-directory
|
|
|
|
maybe-string
|
|
|
|
"The directory where music is located")
|
|
|
|
(playlist-directory
|
|
|
|
maybe-string
|
|
|
|
"The directory where saved playlists are stored")
|
|
|
|
(state-file
|
|
|
|
maybe-string
|
|
|
|
"Specifies if a state file is used and where it is located")
|
|
|
|
(audio-outputs
|
|
|
|
maybe-home-mpd-audio-output-list
|
|
|
|
"Output configurations"))
|
|
|
|
|
|
|
|
(define-class <home-mpd-audio-output> ()
|
|
|
|
(type #:init-keyword #:type)
|
|
|
|
(name #:init-keyword #:name)
|
|
|
|
(path #:init-keyword #:path #:init-value #f)
|
|
|
|
(format #:init-keyword #:format #:init-value #f))
|
|
|
|
|
|
|
|
(define (add-mpd-packages config)
|
|
|
|
(list (home-mpd-configuration-package config)))
|
|
|
|
|
|
|
|
(define (serialize-mpd-configuration config)
|
|
|
|
(serialize-configuration config home-mpd-configuration-fields))
|
|
|
|
|
|
|
|
(define (home-mpd-configuration-file config)
|
|
|
|
(mixed-text-file
|
|
|
|
"mpd.conf"
|
|
|
|
(serialize-mpd-configuration config)))
|
|
|
|
|
|
|
|
(define (home-mpd-shepherd-service config)
|
|
|
|
(list
|
|
|
|
(shepherd-service
|
|
|
|
(documentation "Start MPD")
|
|
|
|
(provision '(mpd))
|
|
|
|
(auto-start? (home-mpd-configuration-auto-start? config))
|
|
|
|
(start
|
|
|
|
#~(make-forkexec-constructor
|
|
|
|
(list #$(file-append (home-mpd-configuration-package config) "/bin/mpd")
|
|
|
|
"--no-daemon"
|
|
|
|
#$(home-mpd-configuration-file config))
|
|
|
|
#:log-file (format #f "~a/.local/var/log/mpd.log" (getenv "HOME"))))
|
|
|
|
(stop #~(make-kill-destructor)))))
|
|
|
|
|
|
|
|
(define home-mpd-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'home-mpd)
|
|
|
|
(extensions
|
|
|
|
(list (service-extension
|
|
|
|
home-profile-service-type
|
|
|
|
add-mpd-packages)
|
|
|
|
(service-extension
|
|
|
|
home-shepherd-service-type
|
|
|
|
home-mpd-shepherd-service)))
|
|
|
|
(compose identity)
|
|
|
|
(default-value (home-mpd-configuration))
|
|
|
|
(description "Install and configure mpd.")))
|
2022-11-08 06:46:07 +01:00
|
|
|
|
|
|
|
(define-configuration home-mpc-update-configuration
|
|
|
|
(package
|
|
|
|
(package mpd-mpc)
|
|
|
|
"Package to use for setting MPC update")
|
|
|
|
(auto-start?
|
|
|
|
(boolean #t)
|
|
|
|
"Should mpc update be started automatically"))
|
|
|
|
|
|
|
|
(define (add-mpc-update-packages config)
|
|
|
|
(list (home-mpc-update-configuration-package config)))
|
|
|
|
|
|
|
|
(define (home-mpc-update-shepherd-service config)
|
|
|
|
(list
|
|
|
|
(shepherd-service
|
|
|
|
(documentation "Update MPD database")
|
|
|
|
(provision '(mpd-update))
|
|
|
|
(auto-start? (home-mpc-update-configuration-auto-start? config))
|
|
|
|
(one-shot? #t)
|
|
|
|
(start
|
|
|
|
#~(make-forkexec-constructor
|
|
|
|
'(#$(file-append mpd-mpc "/bin/mpc") "update"))))))
|
|
|
|
|
|
|
|
(define home-mpc-update-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'home-mpc-update)
|
|
|
|
(extensions
|
|
|
|
(list (service-extension
|
|
|
|
home-profile-service-type
|
|
|
|
add-mpc-update-packages)
|
|
|
|
(service-extension
|
|
|
|
home-shepherd-service-type
|
|
|
|
home-mpc-update-shepherd-service)))
|
|
|
|
(compose identity)
|
|
|
|
(default-value (home-mpc-update-configuration))
|
|
|
|
(description "Install and configure mpc update.")))
|
2023-03-08 08:51:42 +01:00
|
|
|
|
|
|
|
(define-configuration home-mpd-notify-configuration
|
|
|
|
(package
|
|
|
|
(package mpd-notify)
|
|
|
|
"Package to use for setting MPD notify")
|
|
|
|
(auto-start?
|
|
|
|
(boolean #t)
|
|
|
|
"Should mpd notify be started automatically?"))
|
|
|
|
|
|
|
|
(define (add-mpd-notify-packages config)
|
|
|
|
(list (home-mpd-notify-configuration-package config)))
|
|
|
|
|
|
|
|
(define (home-mpd-notify-shepherd-service config)
|
|
|
|
(list
|
|
|
|
(shepherd-service
|
|
|
|
(documentation "Show notifications for MPD player state changes")
|
|
|
|
(provision '(mpd-notify))
|
2023-03-09 08:22:02 +01:00
|
|
|
(requirement '(mpd))
|
2023-03-08 08:51:42 +01:00
|
|
|
(auto-start? (home-mpd-notify-configuration-auto-start? config))
|
|
|
|
(start
|
|
|
|
#~(make-forkexec-constructor
|
|
|
|
(list #$(file-append (home-mpd-notify-configuration-package config) "/bin/mpd-notify"))
|
|
|
|
#:log-file (format #f "~a/.local/var/log/mpd-notify.log" (getenv "HOME"))))
|
|
|
|
(stop #~(make-kill-destructor)))))
|
|
|
|
|
|
|
|
(define home-mpd-notify-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'home-mpd-notify)
|
|
|
|
(extensions
|
|
|
|
(list (service-extension
|
|
|
|
home-profile-service-type
|
|
|
|
add-mpd-notify-packages)
|
|
|
|
(service-extension
|
|
|
|
home-shepherd-service-type
|
|
|
|
home-mpd-notify-shepherd-service)))
|
|
|
|
(compose identity)
|
|
|
|
(default-value (home-mpd-notify-configuration))
|
|
|
|
(description "Install and configure mpd notifications.")))
|