guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/01: services: Add auto-enable? parameter to the bluetooth-service.


From: Ludovic Courtès
Subject: 01/01: services: Add auto-enable? parameter to the bluetooth-service.
Date: Mon, 4 Sep 2017 09:43:06 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit b9f67d6dda12b97b5dce59de3dab230966083a5e
Author: Maxim Cournoyer <address@hidden>
Date:   Mon Aug 7 00:07:53 2017 -0400

    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 (Desktop Services): Document it.
    
    Signed-off-by: Ludovic Courtès <address@hidden>
---
 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 6891739..70a9e36 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -39,6 +39,7 @@ Copyright @copyright{} 2017 address@hidden
 Copyright @copyright{} 2017 Christopher Allan address@hidden
 Copyright @copyright{} 2017 Marius address@hidden
 Copyright @copyright{} 2017 Hartmut Goebel
+Copyright @copyright{} 2017 Maxim address@hidden
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -11818,9 +11819,13 @@ location databases.  See
 web site} for more information.
 @end deffn
 
address@hidden {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.
address@hidden {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}] @
+       address@hidden: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 4918a41..98f1198 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2015 Andy Wingo <address@hidden>
 ;;; Copyright © 2015 Mark H Weaver <address@hidden>
 ;;; Copyright © 2016 Sou Bunnbu <address@hidden>
+;;; Copyright © 2017 Maxim Cournoyer <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -384,32 +385,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?))))
 
 
 ;;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]