Xinglu Chen: 1 gnu: home-services: video: Add Mpv service. 1 files changed, 130 insertions(+), 0 deletions(-)
Xinglu Chen <public@yoctocell.xyz> writes:
Xinglu Chen <public@yoctocell.xyz> writes:
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/23483/mbox | git am -3Learn more about email & git
* gnu/home-services/video: New file. --- gnu/home-services/video.scm | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 gnu/home-services/video.scm diff --git a/gnu/home-services/video.scm b/gnu/home-services/video.scm new file mode 100644 index 0000000..0c6f8cf --- /dev/null +++ b/gnu/home-services/video.scm @@ -0,0 +1,130 @@ +(define-module (gnu home-services video) + #:use-module (gnu home-services files) + #:use-module (gnu home-services) + #:use-module (gnu home-services-utils) + #:use-module (gnu packages video) + #:use-module (gnu services configuration) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (ice-9 match) + #:export (mpv-profile + home-mpv-configuration + home-mpv-service-type)) + +;;; Commentary: +;;; +;;; This module contains services related to video playback and +;;; editing. +;;; +;;; Code: + + +;;; +;;; Mpv. +;;; + +(define (uglify-field-name field-name) + (let ((str (symbol->string field-name))) + (if (string-suffix? "?" str) + (substring str 0 (1- (string-length str)))
string-drop-right is more compact and readable
+ str))) + +(define (serialize-name field-name val) + (format #f "\n[~a]\n" val)) + +(define (serialize-field field-name val) + (cond + ((boolean? val) (serialize-boolean field-name val)) + ((symbol? val) (serialize-symbol field-name val)) + (else #~(format #f "~a=~a\n" #$(uglify-field-name field-name) #$val)))) + +(define (serialize-boolean field-name val) + (serialize-field field-name (boolean->yes-or-no val))) + +(define (serialize-symbol field-name val) + (serialize-field field-name (symbol->string val))) + +(define (serialize-alist field-name val) + #~(string-append #$@(map (match-lambda + ((key . val) (serialize-field key val))) + val))) + +(define-configuration mpv-profile + (name + (string) + "The name of the Mpv profile." + serialize-name) + (options + (alist '()) + "An association list of options to set in the Mpv profile. The format +is the same as the @code{options} field in +@code{home-mpv-configuration}.")) + +(define (serialize-list-of-mpv-profiles field-name val) + #~(string-append #$@(map (lambda (config) + (serialize-configuration + config mpv-profile-fields)) + val))) + +(define (serialize-bindings field-name val) + #~(string-append #$@(map (match-lambda + ((key . val) #~(string-append #$key " " #$val "\n"))) + val))) + +(define list-of-mpv-profiles? + (list-of mpv-profile?)) + +(define-configuration home-mpv-configuration + (package + (package mpv) + "The Mpv package to use.") + (default-options + (alist '()) + "An assocation list of top-level configuration options to set in the +@file{$XDG_CONFIG_HOME/mpv/mpv.conf} file.") + (profiles + (list-of-mpv-profiles '()) + "A list of @code{mpv-profile} records for configuring Mpv profiles.") + (bindings + (alist '()) + "An association list of keybindings to set for Mpv." + serialize-bindings)) + +(define (mpv-files-service config) + `(("config/mpv/mpv.conf" + ,(mixed-text-file + "mpv-config"
I think more consistent naming will be "mpv-mpv.conf". config/git/config -> "git-config" config/sway/config -> "sway-config" config/xmonad/xmonad.hs -> "xmonad-xmonad.hs"
+ (serialize-configuration + config (filter-configuration-fields + home-mpv-configuration-fields '(bindings) #t)))) + ("config/mpv/input.conf" + ,(mixed-text-file + "mpv-input-conf" + (serialize-configuration + config (filter-configuration-fields + home-mpv-configuration-fields '(bindings))))))) + +(define (mpv-profile-service config) + (list (home-mpv-configuration-package config))) + +(define home-mpv-service-type + (service-type (name 'home-mpv) + (extensions + (list (service-extension + home-files-service-type + mpv-files-service) + (service-extension + home-profile-service-type + mpv-profile-service))) + (description "Install and configure Mpv"))) + +(define (generate-home-mpv-documentation)
I've not looked at the related source code deeply, but why we don't use (map configuration->documentation '(home-mpv-configuration mpv-profile)) instead of:
+ (generate-documentation + `((home-mpv-configuration + ,home-mpv-configuration-fields + (mpv-profile home-mpv-profile-configuration)) + (mpv-profile + ,mpv-profile-fields)) + 'home-mpv-configuration)) + + base-commit: 36e5c48d2a332cf1fbe75f60d120021e5a5630be
Thank you for the mpv service!) Applied.
-- 2.32.0
Xinglu Chen <public@yoctocell.xyz> writes: