guix-commits
[Top][All Lists]
Advanced

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

03/03: services: Add upower.


From: Ludovic Courtès
Subject: 03/03: services: Add upower.
Date: Sun, 12 Apr 2015 22:03:20 +0000

civodul pushed a commit to branch core-updates
in repository guix.

commit be234128487306fd922c61fbb0162c53eb5fe6df
Author: Andy Wingo <address@hidden>
Date:   Sat Apr 4 21:49:02 2015 +0200

    services: Add upower.
    
    * gnu-system.am (GNU_SYSTEM_MODULES): Add gnu/services/upower.scm.
    * gnu/services/upower.scm: New file, defining a upower service.
    * doc/guix.texi (Various Services): Mention it.
    
    Co-authored-by: Ludovic Courtès <address@hidden>
---
 doc/guix.texi           |   21 ++++++++
 gnu-system.am           |    1 +
 gnu/services/upower.scm |  122 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 7dbfb66..35b8cc1 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4831,6 +4831,27 @@ Finally, @var{extra-options} is a list of additional 
command-line options
 passed to @command{lircd}.
 @end deffn
 
address@hidden(gnu services upower)} provides a power-management daemon:
+
address@hidden {Monadic Procedure} upower-service [#:upower @var{upower}] @
+                         [#:watts-up-pro? #f] @
+                         [#:poll-batteries? #t] @
+                         [#:ignore-lid? #f] @
+                         [#:use-percentage-for-policy? #f] @
+                         [#:percentage-low 10] @
+                         [#:percentage-critical 3] @
+                         [#:percentage-action 2] @
+                         [#:time-low 1200] @
+                         [#:time-critical 300] @
+                         [#:time-action 120] @
+                         [#:critical-power-action 'hybrid-sleep]
+Return a service that runs @uref{http://upower.freedesktop.org/,
address@hidden, a system-wide monitor for power consumption and battery
+levels, with the given configuration settings.  It implements the
address@hidden D-Bus interface, and is notably used by
+GNOME.
address@hidden deffn
+
 @code{(gnu services colord)} provides a color management service:
 
 @deffn {Monadic Procedure} colord-service [#:colord @var{colord}]
diff --git a/gnu-system.am b/gnu-system.am
index 7b83f4c..afe43bc 100644
--- a/gnu-system.am
+++ b/gnu-system.am
@@ -330,6 +330,7 @@ GNU_SYSTEM_MODULES =                                \
   gnu/services/lirc.scm                                \
   gnu/services/networking.scm                  \
   gnu/services/ssh.scm                         \
+  gnu/services/upower.scm                      \
   gnu/services/xorg.scm                                \
                                                \
   gnu/system.scm                               \
diff --git a/gnu/services/upower.scm b/gnu/services/upower.scm
new file mode 100644
index 0000000..3654c81
--- /dev/null
+++ b/gnu/services/upower.scm
@@ -0,0 +1,122 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 Andy Wingo <address@hidden>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu services upower)
+  #:use-module (gnu services)
+  #:use-module (gnu system shadow)
+  #:use-module (gnu packages gnome)
+  #:use-module (ice-9 match)
+  #:use-module (guix monads)
+  #:use-module (guix store)
+  #:use-module (guix gexp)
+  #:export (upower-service))
+
+;;; Commentary:
+;;;
+;;; This module provides service definitions for the UPower power and battery
+;;; monitoring service.
+;;;
+;;; Code:
+
+(define* (configuration-file #:key watts-up-pro? poll-batteries? ignore-lid?
+                             use-percentage-for-policy? percentage-low
+                             percentage-critical percentage-action
+                             time-low time-critical time-action
+                             critical-power-action)
+  "Return an upower-daemon configuration file."
+  (define (bool value)
+    (if value "true\n" "false\n"))
+
+  (text-file "UPower.conf"
+             (string-append
+              "[UPower]\n"
+              "EnableWattsUpPro=" (bool watts-up-pro?)
+              "NoPollBatteries=" (bool (not poll-batteries?))
+              "IgnoreLid=" (bool ignore-lid?)
+              "UsePercentageForPolicy=" (bool use-percentage-for-policy?)
+              "PercentageLow=" (number->string percentage-low) "\n"
+              "PercentageCritical=" (number->string percentage-critical) "\n"
+              "PercentageAction=" (number->string percentage-action) "\n"
+              "TimeLow=" (number->string time-low) "\n"
+              "TimeCritical=" (number->string time-critical) "\n"
+              "TimeAction=" (number->string time-action) "\n"
+              "CriticalPowerAction=" (match critical-power-action
+                                       ('hybrid-sleep "HybridSleep")
+                                       ('hibernate "Hibernate")
+                                       ('power-off "PowerOff"))
+              "\n")))
+
+(define* (upower-service #:key (upower upower)
+                         (watts-up-pro? #f)
+                         (poll-batteries? #t)
+                         (ignore-lid? #f)
+                         (use-percentage-for-policy? #f)
+                         (percentage-low 10)
+                         (percentage-critical 3)
+                         (percentage-action 2)
+                         (time-low 1200)
+                         (time-critical 300)
+                         (time-action 120)
+                         (critical-power-action 'hybrid-sleep))
+  "Return a service that runs @uref{http://upower.freedesktop.org/,
address@hidden, a system-wide monitor for power consumption and battery
+levels, with the given configuration settings.  It implements the
address@hidden D-Bus interface, and is notably used by GNOME."
+  (mlet %store-monad ((config (configuration-file
+                               #:watts-up-pro? watts-up-pro?
+                               #:poll-batteries? poll-batteries?
+                               #:ignore-lid? ignore-lid?
+                               #:use-percentage-for-policy? 
use-percentage-for-policy?
+                               #:percentage-low percentage-low
+                               #:percentage-critical percentage-critical
+                               #:percentage-action percentage-action
+                               #:time-low time-low
+                               #:time-critical time-critical
+                               #:time-action time-action
+                               #:critical-power-action critical-power-action)))
+    (return
+     (service
+      (documentation "Run the UPower power and battery monitor.")
+      (provision '(upower-daemon))
+      (requirement '(dbus-system udev))
+
+      (start #~(make-forkexec-constructor
+                (list (string-append #$upower "/libexec/upowerd"))
+                #:environment-variables
+                (list (string-append "UPOWER_CONF_FILE_NAME=" #$config))))
+      (stop #~(make-kill-destructor))
+      (activate #~(begin
+                    (use-modules (guix build utils))
+                    (mkdir-p "/var/lib/upower")
+                    (let ((user (getpwnam "upower")))
+                      (chown "/var/lib/upower"
+                             (passwd:uid user) (passwd:gid user)))))
+
+      (user-groups (list (user-group
+                          (name "upower")
+                          (system? #t))))
+      (user-accounts (list (user-account
+                            (name "upower")
+                            (group "upower")
+                            (system? #t)
+                            (comment "UPower daemon user")
+                            (home-directory "/var/empty")
+                            (shell
+                             "/run/current-system/profile/sbin/nologin"))))))))
+
+;;; upower.scm ends here



reply via email to

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