diff mbox series

[bug#60791] gnu: services: Add joycond-service.

Message ID CAJ=RwfZCC=7ZdF2WNs5kGcPh38fub6xN6JbbFew1Q7VD-Yk-Ww@mail.gmail.com
State New
Headers show
Series [bug#60791] gnu: services: Add joycond-service. | expand

Commit Message

Thompson, David Jan. 13, 2023, 10:12 p.m. UTC
Hello Guix,

Joycond is a handy daemon for pairing bluetooth controllers made by
Nintendo. Someone already did the hard work of packaging it, so I
added this simple service to make it easy to use as a system service.

WDYT?

- Dave

Comments

Bruno Victal Jan. 13, 2023, 10:46 p.m. UTC | #1
Hi,

--8<---------------cut here---------------start------------->8---
+@defvar {Scheme Variable} joycond-service-type
+Service type for the joycond service.
+@end defvar
--8<---------------cut here---------------end--------------->8---

Should be `@defvar joycond-service-type'.

--8<---------------cut here---------------start------------->8---
+(define-record-type* <joycond-configuration>
+  joycond-configuration make-joycond-configuration
+  joycond-configuration?
+  (joycond joycond-configuration-joycond (default joycond)))
--8<---------------cut here---------------end--------------->8---

This could be replaced with define-configuration/no-serialization since
the only field here is a package / file-like object. (see [1], [2] for examples)
I'd prefer the field be called 'package' here. 

--8<---------------cut here---------------start------------->8---
+(define (joycond-shepherd-service config)
+  (let ((joycond (joycond-configuration-joycond config)))
+    (list (shepherd-service
+           (documentation "Run joycond.")
+           (provision '(joycond))
+           (requirement '(bluetooth))
+           (start #~(make-forkexec-constructor
+                     (list #$(file-append joycond "/bin/joycond"))))
+           (stop #~(make-kill-destructor))))))
--8<---------------cut here---------------end--------------->8---

You might prefer match-record here but this is okay as well.


[1]: https://issues.guix.gnu.org/60788
[2]: ddclient-configuration in gnu/services/dns.scm


Cheers,
Bruno
Thompson, David Jan. 13, 2023, 11:50 p.m. UTC | #2
Hi Bruno,

Thanks for the review!

On Fri, Jan 13, 2023 at 5:46 PM Bruno Victal <mirai@makinata.eu> wrote:
>
> Hi,
>
> --8<---------------cut here---------------start------------->8---
> +@defvar {Scheme Variable} joycond-service-type
> +Service type for the joycond service.
> +@end defvar
> --8<---------------cut here---------------end--------------->8---
>
> Should be `@defvar joycond-service-type'.

Oh, okay. Guess I missed that change in convention.  There's lots of
'@defvar {Scheme Variable}' in the manual.

> --8<---------------cut here---------------start------------->8---
> +(define-record-type* <joycond-configuration>
> +  joycond-configuration make-joycond-configuration
> +  joycond-configuration?
> +  (joycond joycond-configuration-joycond (default joycond)))
> --8<---------------cut here---------------end--------------->8---
>
> This could be replaced with define-configuration/no-serialization since
> the only field here is a package / file-like object. (see [1], [2] for examples)
> I'd prefer the field be called 'package' here.

Ahhhh unhygienic macros! Not a fan but I see that this macro is the
preferred thing these days so okay, changed!  I also prefer the field
to be called 'package' so I've changed it! When I looked around at
some other services they used the package name as the field name so I
followed their lead.

> --8<---------------cut here---------------start------------->8---
> +(define (joycond-shepherd-service config)
> +  (let ((joycond (joycond-configuration-joycond config)))
> +    (list (shepherd-service
> +           (documentation "Run joycond.")
> +           (provision '(joycond))
> +           (requirement '(bluetooth))
> +           (start #~(make-forkexec-constructor
> +                     (list #$(file-append joycond "/bin/joycond"))))
> +           (stop #~(make-kill-destructor))))))
> --8<---------------cut here---------------end--------------->8---
>
> You might prefer match-record here but this is okay as well.

If I was destructuring many record fields I'd use it.

Updated patch attached.

Thanks!

- Dave
Bruno Victal Jan. 14, 2023, 4:47 a.m. UTC | #3
--8<---------------cut here---------------start------------->8---
joycond-configuration-joycond
--8<---------------cut here---------------end--------------->8---

Doesn't need to be exported, commit message could be amended as well.


--8<---------------cut here---------------start------------->8---
+@table @asis
+@item @code{joycond} (default: @code{joycond})
+The joycond package to use.
+@end table
+@end deftp
--8<---------------cut here---------------end--------------->8---

@code should be updated to the new `package' field name.


Overall LTGM.


Cheers,
Bruno
Thompson, David Jan. 14, 2023, 1 p.m. UTC | #4
On Fri, Jan 13, 2023 at 11:47 PM Bruno Victal <mirai@makinata.eu> wrote:
>
> --8<---------------cut here---------------start------------->8---
> joycond-configuration-joycond
> --8<---------------cut here---------------end--------------->8---
>
> Doesn't need to be exported, commit message could be amended as well.
>
>
> --8<---------------cut here---------------start------------->8---
> +@table @asis
> +@item @code{joycond} (default: @code{joycond})
> +The joycond package to use.
> +@end table
> +@end deftp
> --8<---------------cut here---------------end--------------->8---
>
> @code should be updated to the new `package' field name.
>
>
> Overall LTGM.

Thanks for catching my silly late-evening fixup oversights.  Fixed all
of that and pushed!

- Dave
diff mbox series

Patch

From 247ce9cd302d3ff196eae662d27f5a37ac6ce376 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Fri, 13 Jan 2023 17:04:21 -0500
Subject: [PATCH] gnu: services: Add joycond-service.

* gnu/services/games.scm (<joycond-configuration>): New record type.
(joycond-configuration, joycond-configuration?, joycond-configuration-joycond,
joycond-shepherd-service): New procedures.
(joycond-service-type): New variable.
* doc/guix.texi (Game Services): Document it.
---
 doc/guix.texi          | 19 +++++++++++++++++++
 gnu/services/games.scm | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 751d0957d8..4aec5895d2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36277,6 +36277,25 @@  like to serve.
 @node Game Services
 @subsection Game Services
 
+@subsubheading Joycond service
+@cindex joycond
+The joycond service allows the pairing of Nintendo joycon game
+controllers over Bluetooth. (@pxref{Desktop Services} for setting up
+Bluetooth.)
+
+@deftp {Data Type} joycond-configuration
+Data type representing the configuration of @command{joycond}.
+
+@table @asis
+@item @code{joycond} (default: @code{joycond})
+The joycond package to use.
+@end table
+@end deftp
+
+@defvar {Scheme Variable} joycond-service-type
+Service type for the joycond service.
+@end defvar
+
 @subsubheading The Battle for Wesnoth Service
 @cindex wesnothd
 @uref{https://wesnoth.org, The Battle for Wesnoth} is a fantasy, turn
diff --git a/gnu/services/games.scm b/gnu/services/games.scm
index 6c2af44b49..adccddfb99 100644
--- a/gnu/services/games.scm
+++ b/gnu/services/games.scm
@@ -30,10 +30,45 @@  (define-module (gnu services games)
   #:use-module (guix modules)
   #:use-module (guix records)
   #:use-module (ice-9 match)
-  #:export (wesnothd-configuration
+  #:export (joycond-configuration
+            joycond-configuration?
+            joycond-configuration-joycond
+            joycond-service-type
+
+            wesnothd-configuration
             wesnothd-configuration?
             wesnothd-service-type))
 
+;;;
+;;; Joycond
+;;;
+
+(define-record-type* <joycond-configuration>
+  joycond-configuration make-joycond-configuration
+  joycond-configuration?
+  (joycond joycond-configuration-joycond (default joycond)))
+
+(define (joycond-shepherd-service config)
+  (let ((joycond (joycond-configuration-joycond config)))
+    (list (shepherd-service
+           (documentation "Run joycond.")
+           (provision '(joycond))
+           (requirement '(bluetooth))
+           (start #~(make-forkexec-constructor
+                     (list #$(file-append joycond "/bin/joycond"))))
+           (stop #~(make-kill-destructor))))))
+
+(define joycond-service-type
+  (service-type
+   (name 'joycond)
+   (description
+    "Run @command{joycond} for pairing Nintendo joycons via Bluetooth.")
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             joycond-shepherd-service)))
+   (default-value (joycond-configuration))))
+
+
 ;;;
 ;;; The Battle for Wesnoth server
 ;;;
-- 
2.38.1