Subject: [PATCH 2/2] home-mpv-configuration: Support file-like for file fields.

From: Tomas Volf <[email-masked]>
Date: Mon, 26 May 2025 23:19:02 +0200

* gnu/home/services/mpv.scm (serialize-mpv/file, mpv/file?): New procedures.
(ao-null-latency, audio-file-paths, audio-files, bluray-device, cdda-device)
(chapters-file, cookies-file, cover-art-files, demuxer-cache-dir, dump-stats)
(dvbin-file, dvd-device, external-files, glsl-shaders, gpu-shader-cache-dir)
(icc-cache-dir, icc-profile, image-lut, include, input-conf, input-ipc-server)
(log-file, lut, ordered-chapters-files, osd-fonts-dir, screenshot-directory)
(scripts, stream-dump, sub-ass-styles, sub-file-paths, sub-files)
(sub-fonts-dir, target-lut, tls-ca-file, tls-cert-file, tls-key-file):
(vo-image-outdir, watch-history-path, watch-later-directory): Change type.
* doc/guix.texi (mpv Media Player): Document it.

Reported-by: Sergey Trofimov <[email-masked]>
Change-Id: I7e55b306104c235d165ab138397b767f1af5c124
---
 doc/guix.texi             |  3 +-
 gnu/home/services/mpv.scm | 94 +++++++++++++++++++++++----------------
 2 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 40a1bddf52..4c513f500c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -51131,7 +51131,8 @@ mpv Media Player
 
 Other types accept strings, with validation of the values where possible
 (e.g. type @samp{Color} is validated, but type @samp{Audio channels or
-channel map} is not).
+channel map} is not).  If an option is marked as taking a file, values
+satisfying @code{file-like?} can also be used.
 
 The full list of currently supported keyword arguments is below.  For
 the types, allowed values and full description please refer to the
diff --git a/gnu/home/services/mpv.scm b/gnu/home/services/mpv.scm
index b6c640a38b..50d3f06c46 100644
--- a/gnu/home/services/mpv.scm
+++ b/gnu/home/services/mpv.scm
@@ -87,6 +87,14 @@ (define (serialize-mpv/string field-name value)
 (define mpv/string?
   string?)
 
+(define (serialize-mpv/file field-name value)
+  #~(string-append #$(symbol->string field-name)
+                   "="
+                   #$value
+                   "\n"))
+(define (mpv/file? value)
+  (or (file-like? value) (string? value)))
+
 (define (serialize-mpv/float field-name value)
   #~(string-append #$(symbol->string field-name)
                    "="
@@ -216,6 +224,14 @@ (define (serialize-mpv/list-of-string field-name lst)
 (define (mpv/list-of-string? lst)
   (every mpv/string? lst))
 
+(define (serialize-mpv/list-of-file field-name lst)
+  #~(string-append #$(symbol->string field-name)
+                   "="
+                   (string-join '#$lst ",")
+                   "\n"))
+(define (mpv/list-of-file? lst)
+  (every mpv/file? lst))
+
 (define (serialize-mpv/list-of-key-value field-name lst)
   #~(string-append #$(symbol->string field-name)
                    "="
@@ -378,7 +394,7 @@ (define-opt
   (<= val 10000))
 (define-opt ao-null-untimed? boolean)
 (define-opt ao-pcm-append? boolean)
-(define-opt ao-pcm-file string)
+(define-opt ao-pcm-file file)
 (define-opt ao-pcm-waveheader? boolean)
 (define-opt archive-exts list-of-string)
 (define-opt
@@ -414,8 +430,8 @@ (define-opt
   audio-file-auto
   enumeration
   (memq val '(no exact fuzzy all)))
-(define-opt audio-file-paths list-of-string)
-(define-opt audio-files list-of-string)
+(define-opt audio-file-paths list-of-file)
+(define-opt audio-files list-of-file)
 (define-opt audio-format audio-format)
 (define-opt audio-normalize-downmix? boolean)
 (define-opt audio-pitch-correction? boolean)
@@ -479,7 +495,7 @@ (define-opt
   blend-subtitles
   enumeration
   (memq val '(no yes video)))
-(define-opt bluray-device string)
+(define-opt bluray-device file)
 (define-opt border? boolean)
 (define-opt
   border-background
@@ -504,7 +520,7 @@ (define-opt
   (<= val 3.4028234663853e38))
 (define-opt cache-secs double (>= val 0))
 (define-opt cdda-cdtext? boolean)
-(define-opt cdda-device string)
+(define-opt cdda-device file)
 (define-opt
   cdda-overlap
   integer
@@ -535,7 +551,7 @@ (define-opt
   (>= val 0)
   (<= val 10000))
 (define-opt chapter-seek-threshold double)
-(define-opt chapters-file string)
+(define-opt chapters-file file)
 (define-opt
   clipboard-backends
   list-of-object-setting)
@@ -551,7 +567,7 @@ (define-opt
   (>= val -100)
   (<= val 100))
 (define-opt cookies? boolean)
-(define-opt cookies-file string)
+(define-opt cookies-file file)
 (define-opt
   corner-rounding
   float
@@ -563,7 +579,7 @@ (define-opt
   cover-art-auto
   enumeration
   (memq val '(no exact fuzzy all)))
-(define-opt cover-art-files list-of-string)
+(define-opt cover-art-files list-of-file)
 (define-opt cover-art-whitelist list-of-string)
 (define-opt
   cscale
@@ -692,7 +708,7 @@ (define-opt
   demuxer-backward-playback-step
   double
   (>= val 0))
-(define-opt demuxer-cache-dir string)
+(define-opt demuxer-cache-dir file)
 (define-opt
   demuxer-cache-unlink-files
   enumeration
@@ -955,14 +971,14 @@ (define-opt
   float
   (>= val 0)
   (<= val 1))
-(define-opt dump-stats string)
+(define-opt dump-stats file)
 (define-opt
   dvbin-card
   integer
   (>= val 0)
   (<= val 15))
 (define-opt dvbin-channel-switch-offset integer)
-(define-opt dvbin-file string)
+(define-opt dvbin-file file)
 (define-opt dvbin-full-transponder? boolean)
 (define-opt dvbin-prog string)
 (define-opt
@@ -975,7 +991,7 @@ (define-opt
   integer
   (>= val 1)
   (<= val 99))
-(define-opt dvd-device string)
+(define-opt dvd-device file)
 (define-opt dvd-speed integer)
 (define-opt
   edition
@@ -1002,7 +1018,7 @@ (define-opt
   end
   relative-time-or-percent-position)
 (define-opt error-diffusion string)
-(define-opt external-files list-of-string)
+(define-opt external-files list-of-file)
 (define-opt fbo-format string)
 (define-opt
   focus-on
@@ -1065,7 +1081,7 @@ (define-opt
   (memq val '(no yes weak)))
 (define-opt geometry window-geometry)
 (define-opt glsl-shader-opts list-of-key-value)
-(define-opt glsl-shaders list-of-string)
+(define-opt glsl-shaders list-of-file)
 (define-opt gpu-api list-of-object-setting)
 (define-opt gpu-context list-of-object-setting)
 (define-opt gpu-debug? boolean)
@@ -1075,7 +1091,7 @@ (define-opt
   (memq val '(auto yes no)))
 (define-opt gpu-hwdec-interop string)
 (define-opt gpu-shader-cache? boolean)
-(define-opt gpu-shader-cache-dir string)
+(define-opt gpu-shader-cache-dir file)
 (define-opt gpu-sw? boolean)
 (define-opt
   gpu-tex-pad-x
@@ -1155,14 +1171,14 @@ (define-opt
            (<= val 2147483647))))
 (define-opt icc-3dlut-size string)
 (define-opt icc-cache? boolean)
-(define-opt icc-cache-dir string)
+(define-opt icc-cache-dir file)
 (define-opt
   icc-force-contrast
   enumeration
   (or (memq val '(no inf))
       (and (integer? val) (>= val 0) (<= val 1000000))))
 (define-opt icc-intent integer)
-(define-opt icc-profile string)
+(define-opt icc-profile file)
 (define-opt icc-profile-auto? boolean)
 (define-opt icc-use-luma? boolean)
 (define-opt
@@ -1177,13 +1193,13 @@ (define-opt
   double
   (>= val 0))
 (define-opt image-exts list-of-string)
-(define-opt image-lut string)
+(define-opt image-lut file)
 (define-opt
   image-lut-type
   enumeration
   (memq val '(auto native normalized conversion)))
 (define-opt image-subs-video-resolution? boolean)
-(define-opt include string)
+(define-opt include file)
 (define-opt
   index
   enumeration
@@ -1194,7 +1210,7 @@ (define-opt input-ar-rate integer)
 (define-opt input-builtin-bindings? boolean)
 (define-opt input-builtin-dragging? boolean)
 (define-opt input-commands list-of-string)
-(define-opt input-conf string)
+(define-opt input-conf file)
 (define-opt input-cursor? boolean)
 (define-opt input-cursor-passthrough? boolean)
 (define-opt input-default-bindings? boolean)
@@ -1206,7 +1222,7 @@ (define-opt
 (define-opt input-dragging-deadzone integer)
 (define-opt input-ime? boolean)
 (define-opt input-ipc-client string)
-(define-opt input-ipc-server string)
+(define-opt input-ipc-server file)
 (define-opt
   input-key-fifo-size
   integer
@@ -1256,7 +1272,7 @@ (define-opt load-scripts? boolean)
 (define-opt load-select? boolean)
 (define-opt load-stats-overlay? boolean)
 (define-opt load-unsafe-playlists? boolean)
-(define-opt log-file string)
+(define-opt log-file file)
 (define-opt
   loop-file
   enumeration
@@ -1267,7 +1283,7 @@ (define-opt
   enumeration
   (or (memq val '(no inf yes force))
       (and (integer? val) (>= val 1) (<= val 10000))))
-(define-opt lut string)
+(define-opt lut file)
 (define-opt
   lut-type
   enumeration
@@ -1328,7 +1344,7 @@ (define-opt opengl-swapinterval integer)
 (define-opt opengl-waitvsync? boolean)
 (define-opt orawts? boolean)
 (define-opt ordered-chapters? boolean)
-(define-opt ordered-chapters-files string)
+(define-opt ordered-chapters-files file)
 (define-opt oremove-metadata list-of-string)
 (define-opt osc? boolean)
 (define-opt
@@ -1407,7 +1423,7 @@ (define-opt
   float
   (>= val 1)
   (<= val 9000))
-(define-opt osd-fonts-dir string)
+(define-opt osd-fonts-dir file)
 (define-opt osd-fractions? boolean)
 (define-opt osd-italic? boolean)
 (define-opt
@@ -1640,7 +1656,7 @@ (define-opt
   screenshot-avif-opts
   list-of-key-value)
 (define-opt screenshot-avif-pixfmt string)
-(define-opt screenshot-directory string)
+(define-opt screenshot-directory file)
 (define-opt
   screenshot-format
   enumeration
@@ -1689,7 +1705,7 @@ (define-opt
   (>= val 0)
   (<= val 100))
 (define-opt script-opts list-of-key-value)
-(define-opt scripts list-of-string)
+(define-opt scripts list-of-file)
 (define-opt
   secondary-sid
   enumeration
@@ -1752,7 +1768,7 @@ (define-opt
   byte-size
   (>= val 4096)
   (<= val 536870912))
-(define-opt stream-dump string)
+(define-opt stream-dump file)
 (define-opt stream-lavf-o list-of-key-value)
 (define-opt stream-record string)
 (define-opt stretch-dvd-subs? boolean)
@@ -1782,7 +1798,7 @@ (define-opt sub-ass-scale-with-window? boolean)
 (define-opt
   sub-ass-style-overrides
   list-of-string)
-(define-opt sub-ass-styles string)
+(define-opt sub-ass-styles file)
 (define-opt
   sub-ass-use-video-data
   enumeration
@@ -1819,8 +1835,8 @@ (define-opt sub-color color)
 (define-opt sub-create-cc-track? boolean)
 (define-opt sub-delay float)
 (define-opt sub-demuxer string)
-(define-opt sub-file-paths list-of-string)
-(define-opt sub-files list-of-string)
+(define-opt sub-file-paths list-of-file)
+(define-opt sub-files list-of-file)
 (define-opt sub-filter-jsre list-of-string)
 (define-opt sub-filter-regex list-of-string)
 (define-opt sub-filter-regex-enable? boolean)
@@ -1840,7 +1856,7 @@ (define-opt
   float
   (>= val 1)
   (<= val 9000))
-(define-opt sub-fonts-dir string)
+(define-opt sub-fonts-dir file)
 (define-opt sub-forced-events-only? boolean)
 (define-opt sub-fps float)
 (define-opt
@@ -1993,7 +2009,7 @@ (define-opt
                film-c
                aces-ap0
                aces-ap1)))
-(define-opt target-lut string)
+(define-opt target-lut file)
 (define-opt
   target-peak
   enumeration
@@ -2064,9 +2080,9 @@ (define-opt term-title string)
 (define-opt terminal? boolean)
 (define-opt title string)
 (define-opt title-bar? boolean)
-(define-opt tls-ca-file string)
-(define-opt tls-cert-file string)
-(define-opt tls-key-file string)
+(define-opt tls-ca-file file)
+(define-opt tls-cert-file file)
+(define-opt tls-key-file file)
 (define-opt tls-verify? boolean)
 (define-opt
   tone-mapping
@@ -2373,7 +2389,7 @@ (define-opt
   integer
   (>= val 1)
   (<= val 9))
-(define-opt vo-image-outdir string)
+(define-opt vo-image-outdir file)
 (define-opt
   vo-image-png-compression
   integer
@@ -2521,8 +2537,8 @@ (define-opt
   enumeration
   (memq val
         '(auto fifo fifo-relaxed mailbox immediate)))
-(define-opt watch-history-path string)
-(define-opt watch-later-directory string)
+(define-opt watch-history-path file)
+(define-opt watch-later-directory file)
 (define-opt watch-later-options list-of-string)
 (define-opt wayland-app-id string)
 (define-opt
-- 
2.49.0