~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
5 2

[PATCH] gnu: home-services: video: Add Mpv service.

Details
Message ID
<95c37cdddbedc0bbaacb569ddd49cb6bb1ac03f9.1624715488.git.public@yoctocell.xyz>
DKIM signature
pass
Download raw message
Patch: +130 -0
* 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)))
        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"
       (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)
  (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
-- 
2.32.0
Details
Message ID
<87k0meqxvn.fsf@trop.in>
In-Reply-To
<95c37cdddbedc0bbaacb569ddd49cb6bb1ac03f9.1624715488.git.public@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
Xinglu Chen <public@yoctocell.xyz> writes:

> * 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.
Details
Message ID
<87czs63qje.fsf@yoctocell.xyz>
In-Reply-To
<87k0meqxvn.fsf@trop.in> (view parent)
DKIM signature
pass
Download raw message
On Mon, Jun 28 2021, Andrew Tropin wrote:

>> +(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"

Ah, that does make sense.

>> +       (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:

By just using ‘configuration->documentation’ we cannot express the
hierachy (see the docs for ‘getmail-configuration’ to get a better
idea):

  home-mpv-configuration
    mpv-profile

everything gets displayed in a flat list like this:

  home-mpv-configuration
  mpv-profile

Since ‘mpv-profile’ is designed to used in the ‘profiles’ field of
‘home-mpv-configuration’, I think it makes sense to make it a
hierarchy.  If there also was a ‘home-mpv-extension’ record or something
like that, it would make sense to put it at the same level as
‘home-mpv-configuration’.

  home-mpv-configuration
    mpv-profile
  home-mpv-extension

> Thank you for the mpv service!) Applied.

You are welcome!
Details
Message ID
<87h7hhqk1f.fsf@trop.in>
In-Reply-To
<87czs63qje.fsf@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
Xinglu Chen <public@yoctocell.xyz> writes:

> On Mon, Jun 28 2021, Andrew Tropin wrote:
>
>>> +(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"
>
> Ah, that does make sense.
>
>>> +       (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:
>
> By just using ‘configuration->documentation’ we cannot express the
> hierachy (see the docs for ‘getmail-configuration’ to get a better
> idea):
>
>   home-mpv-configuration
>     mpv-profile
>
> everything gets displayed in a flat list like this:
>
>   home-mpv-configuration
>   mpv-profile
>
> Since ‘mpv-profile’ is designed to used in the ‘profiles’ field of
> ‘home-mpv-configuration’, I think it makes sense to make it a
> hierarchy.  If there also was a ‘home-mpv-extension’ record or something
> like that, it would make sense to put it at the same level as
> ‘home-mpv-configuration’.
>
>   home-mpv-configuration
>     mpv-profile
>   home-mpv-extension
>

I see, make sense.  Just an idea: probably it's possible to make
configuration->documentation create hierarchy based on fields types.

One more question.  Can we wrap (generate-documentation ...) into
(display), to make (generate-home-mpv-documentation) print a ready to
use documentation instead of string with a lots of \n inside?

>> Thank you for the mpv service!) Applied.
>
> You are welcome!
Details
Message ID
<878s2sbiyd.fsf@yoctocell.xyz>
In-Reply-To
<87h7hhqk1f.fsf@trop.in> (view parent)
DKIM signature
pass
Download raw message
On Tue, Jun 29 2021, Andrew Tropin wrote:

>>> 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:
>>
>> By just using ‘configuration->documentation’ we cannot express the
>> hierachy (see the docs for ‘getmail-configuration’ to get a better
>> idea):
>>
>>   home-mpv-configuration
>>     mpv-profile
>>
>> everything gets displayed in a flat list like this:
>>
>>   home-mpv-configuration
>>   mpv-profile
>>
>> Since ‘mpv-profile’ is designed to used in the ‘profiles’ field of
>> ‘home-mpv-configuration’, I think it makes sense to make it a
>> hierarchy.  If there also was a ‘home-mpv-extension’ record or something
>> like that, it would make sense to put it at the same level as
>> ‘home-mpv-configuration’.
>>
>>   home-mpv-configuration
>>     mpv-profile
>>   home-mpv-extension
>>
>
> I see, make sense.  Just an idea: probably it's possible to make
> configuration->documentation create hierarchy based on fields types.
>
> One more question.  Can we wrap (generate-documentation ...) into
> (display), to make (generate-home-mpv-documentation) print a ready to
> use documentation instead of string with a lots of \n inside?

That would probably be a good idea. :)
Details
Message ID
<87pmw43q2n.fsf@trop.in>
In-Reply-To
<878s2sbiyd.fsf@yoctocell.xyz> (view parent)
DKIM signature
missing
Download raw message
Xinglu Chen <public@yoctocell.xyz> writes:

> On Tue, Jun 29 2021, Andrew Tropin wrote:
>
>>>> 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:
>>>
>>> By just using ‘configuration->documentation’ we cannot express the
>>> hierachy (see the docs for ‘getmail-configuration’ to get a better
>>> idea):
>>>
>>>   home-mpv-configuration
>>>     mpv-profile
>>>
>>> everything gets displayed in a flat list like this:
>>>
>>>   home-mpv-configuration
>>>   mpv-profile
>>>
>>> Since ‘mpv-profile’ is designed to used in the ‘profiles’ field of
>>> ‘home-mpv-configuration’, I think it makes sense to make it a
>>> hierarchy.  If there also was a ‘home-mpv-extension’ record or something
>>> like that, it would make sense to put it at the same level as
>>> ‘home-mpv-configuration’.
>>>
>>>   home-mpv-configuration
>>>     mpv-profile
>>>   home-mpv-extension
>>>
>>
>> I see, make sense.  Just an idea: probably it's possible to make
>> configuration->documentation create hierarchy based on fields types.
>>
>> One more question.  Can we wrap (generate-documentation ...) into
>> (display), to make (generate-home-mpv-documentation) print a ready to
>> use documentation instead of string with a lots of \n inside?
>
> That would probably be a good idea. :)

Cool, will add it a not to the manual, when will be writing "Declaring
new home-services" section.
Reply to thread Export thread (mbox)