unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#28007] [PATCH] Add auto-enable? parameter to the bluetooth-service
@ 2017-08-08  2:10 Maxim Cournoyer
  2017-09-04 13:43 ` bug#28007: " Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Maxim Cournoyer @ 2017-08-08  2:10 UTC (permalink / raw)
  To: 28007

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

Hello Guix,

Here's a patch that enables bluetooth controllers automatically (power
them on) without having to manually do "power on" with bluetoothctl
everytime the system is rebooted.

Thank you,

Maxim


[-- Attachment #2: 0001-services-Add-auto-enable-parameter-to-the-bluetooth-.patch --]
[-- Type: text/x-patch, Size: 5672 bytes --]

From 3631a5f6742b31ac173a6d32cb3e7074f1ce0aa5 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 7 Aug 2017 00:07:53 -0400
Subject: [PATCH] services: Add auto-enable? parameter to the bluetooth-service

* gnu/services/desktop.scm (bluetooth-configuration): New record.
(bluetooth-shepherd-service): Use it.
(bluetooth-directory): New method.
(bluetooth-service-type): Use it to extend the etc-service-type service.
(bluetooth-service): Add `auto-enable?' parameter.
* doc/guix.texi: Document it.
---
 doc/guix.texi            | 11 ++++++++---
 gnu/services/desktop.scm | 50 +++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6b4b19d0c..63186f6ab 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -39,6 +39,7 @@ Copyright @copyright{} 2017 humanitiesNerd@*
 Copyright @copyright{} 2017 Christopher Allan Webber@*
 Copyright @copyright{} 2017 Marius Bakke@*
 Copyright @copyright{} 2017 Hartmut Goebel
+Copyright @copyright{} 2017 Maxim Cournoyer@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -11712,9 +11713,13 @@ location databases.  See
 web site} for more information.
 @end deffn
 
-@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
-Return a service that runs the @command{bluetoothd} daemon, which manages
-all the Bluetooth devices and provides a number of D-Bus interfaces.
+@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}] @
+       [@w{#:auto-enable? #f}]
+Return a service that runs the @command{bluetoothd} daemon, which
+manages all the Bluetooth devices and provides a number of D-Bus
+interfaces.  When AUTO-ENABLE? is true, the bluetooth controller is
+powered automatically at boot, which can be useful when using a
+bluetooth keyboard or mouse.
 
 Users need to be in the @code{lp} group to access the D-Bus service.
 @end deffn
diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm
index 50a561bf5..8b6c2793c 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
 ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
+;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -381,32 +382,67 @@ site} for more information."
 ;;; Bluetooth.
 ;;;
 
-(define (bluetooth-shepherd-service bluez)
+(define-record-type* <bluetooth-configuration>
+  bluetooth-configuration make-bluetooth-configuration
+  bluetooth-configuration?
+  (bluez bluetooth-configuration-bluez (default bluez))
+  (auto-enable? bluetooth-configuration-auto-enable? (default #f)))
+
+(define (bluetooth-configuration-file config)
+  "Return a configuration file for the systemd bluetooth service, as a string."
+  (string-append
+   "[Policy]\n"
+   "AutoEnable=" (bool (bluetooth-configuration-auto-enable?
+                        config))))
+
+(define (bluetooth-directory config)
+  (computed-file "etc-bluetooth"
+                 #~(begin
+                     (mkdir #$output)
+                     (chdir #$output)
+                     (call-with-output-file "main.conf"
+                       (lambda (port)
+                         (display #$(bluetooth-configuration-file config)
+                                  port))))))
+
+(define (bluetooth-shepherd-service config)
   "Return a shepherd service for @command{bluetoothd}."
   (shepherd-service
    (provision '(bluetooth))
    (requirement '(dbus-system udev))
    (documentation "Run the bluetoothd daemon.")
    (start #~(make-forkexec-constructor
-             (string-append #$bluez "/libexec/bluetooth/bluetoothd")))
+             (string-append #$(bluetooth-configuration-bluez config)
+                            "/libexec/bluetooth/bluetoothd")))
    (stop #~(make-kill-destructor))))
 
 (define bluetooth-service-type
   (service-type
    (name 'bluetooth)
    (extensions
-    (list (service-extension dbus-root-service-type list)
-          (service-extension udev-service-type list)
+    (list (service-extension dbus-root-service-type
+                             (compose list bluetooth-configuration-bluez))
+          (service-extension udev-service-type
+                             (compose list bluetooth-configuration-bluez))
+          (service-extension etc-service-type
+                             (lambda (config)
+                               `(("bluetooth"
+                                  ,(bluetooth-directory config)))))
           (service-extension shepherd-root-service-type
                              (compose list bluetooth-shepherd-service))))))
 
-(define* (bluetooth-service #:key (bluez bluez))
+(define* (bluetooth-service #:key (bluez bluez) (auto-enable? #f))
   "Return a service that runs the @command{bluetoothd} daemon, which manages
-all the Bluetooth devices and provides a number of D-Bus interfaces.
+all the Bluetooth devices and provides a number of D-Bus interfaces.  When
+AUTO-ENABLE? is true, the bluetooth controller is powered automatically at
+boot.
 
 Users need to be in the @code{lp} group to access the D-Bus service.
 "
-  (service bluetooth-service-type bluez))
+  (service bluetooth-service-type
+           (bluetooth-configuration
+            (bluez bluez)
+            (auto-enable? auto-enable?))))
 
 \f
 ;;;
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#28007: [PATCH] Add auto-enable? parameter to the bluetooth-service
  2017-08-08  2:10 [bug#28007] [PATCH] Add auto-enable? parameter to the bluetooth-service Maxim Cournoyer
@ 2017-09-04 13:43 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2017-09-04 13:43 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: 28007-done

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

>>From 3631a5f6742b31ac173a6d32cb3e7074f1ce0aa5 Mon Sep 17 00:00:00 2001
> From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
> Date: Mon, 7 Aug 2017 00:07:53 -0400
> Subject: [PATCH] services: Add auto-enable? parameter to the bluetooth-service
>
> * gnu/services/desktop.scm (bluetooth-configuration): New record.
> (bluetooth-shepherd-service): Use it.
> (bluetooth-directory): New method.
> (bluetooth-service-type): Use it to extend the etc-service-type service.
> (bluetooth-service): Add `auto-enable?' parameter.
> * doc/guix.texi: Document it.

Pushed as b9f67d6dda12b97b5dce59de3dab230966083a5e, thanks!

Ludo'.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-04 13:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-08  2:10 [bug#28007] [PATCH] Add auto-enable? parameter to the bluetooth-service Maxim Cournoyer
2017-09-04 13:43 ` bug#28007: " Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).