home: Add home-batsignal-service-type.

* gnu/home/services/pm.scm (home-batsignal-service-type): New variable.
(home-batsignal-configuration): New record type.
* doc/guix.texi: Document them.
* gnu/local.mk: Add gnu/home/services/pm.scm.
This commit is contained in:
( via Guix-patches via 2022-09-29 17:40:20 +01:00 committed by Andrew Tropin
parent 224fd038f2
commit 7030f592c6
No known key found for this signature in database
GPG key ID: 2208D20958C1DEB0
3 changed files with 231 additions and 6 deletions

View file

@ -107,6 +107,7 @@ Copyright @copyright{} 2022 Karl Hallsby@*
Copyright @copyright{} 2022 Justin Veilleux@*
Copyright @copyright{} 2022 Reily Siegel@*
Copyright @copyright{} 2022 Simon Streit@*
Copyright @copyright{} 2022 (@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@ -40154,12 +40155,13 @@ services)}.
@menu
* Essential Home Services:: Environment variables, packages, on-* scripts.
* Shells: Shells Home Services. POSIX shells, Bash, Zsh.
* Mcron: Mcron Home Service. Scheduled User's Job Execution.
* Shepherd: Shepherd Home Service. Managing User's Daemons.
* SSH: Secure Shell. Setting up the secure shell client.
* Desktop: Desktop Home Services. Services for graphical environments.
* Guix: Guix Home Services. Services for Guix.
* Shells: Shells Home Services. POSIX shells, Bash, Zsh.
* Mcron: Mcron Home Service. Scheduled User's Job Execution.
* Power Management: Power Management Home Services. Services for battery power.
* Shepherd: Shepherd Home Service. Managing User's Daemons.
* SSH: Secure Shell. Setting up the secure shell client.
* Desktop: Desktop Home Services. Services for graphical environments.
* Guix: Guix Home Services. Services for Guix.
@end menu
@c In addition to that Home Services can provide
@ -40607,6 +40609,82 @@ specifications,, mcron, GNU@tie{}mcron}).
@end table
@end deftp
@node Power Management Home Services
@subsection Power Management Home Services
@cindex power management
The @code{(gnu home services pm)} module provides home services
pertaining to battery power.
@defvr {Scheme Variable} home-batsignal-service-type
Service for @code{batsignal}, a program that monitors battery levels
and warns the user through desktop notifications when their battery
is getting low. You can also configure a command to be run when the
battery level passes a point deemed ``dangerous''. This service is
configured with the @code{home-batsignal-configuration} record.
@end defvr
@deftp {Data Type} home-batsignal-configuration
Data type representing the configuration for batsignal.
@table @asis
@item @code{warning-level} (default: @code{15})
The battery level to send a warning message at.
@item @code{warning-message} (default: @code{#f})
The message to send as a notification when the battery level reaches
the @code{warning-level}. Setting to @code{#f} uses the default
message.
@item @code{critical-level} (default: @code{5})
The battery level to send a critical message at.
@item @code{critical-message} (default: @code{#f})
The message to send as a notification when the battery level reaches
the @code{critical-level}. Setting to @code{#f} uses the default
message.
@item @code{danger-level} (default: @code{2})
The battery level to run the @code{danger-command} at.
@item @code{danger-command} (default: @code{#f})
The command to run when the battery level reaches the @code{danger-level}.
Setting to @code{#f} disables running the command entirely.
@item @code{full-level} (default: @code{#f})
The battery level to send a full message at. Setting to @code{#f}
disables sending the full message entirely.
@item @code{full-message} (default: @code{#f})
The message to send as a notification when the battery level reaches
the @code{full-level}. Setting to @code{#f} uses the default message.
@item @code{batteries} (default: @code{'()})
The batteries to monitor. Setting to @code{'()} tries to find batteries
automatically.
@item @code{poll-delay} (default: @code{60})
The time in seconds to wait before checking the batteries again.
@item @code{icon} (default: @code{#f})
A file-like object to use as the icon for battery notifications. Setting
to @code{#f} disables notification icons entirely.
@item @code{notifications?} (default: @code{#t})
Whether to send any notifications.
@item @code{notifications-expire?} (default: @code{#f})
Whether notifications sent expire after a time.
@item @code{notification-command} (default: @code{#f})
Command to use to send messages. Setting to @code{#f} sends a notification
through @code{libnotify}.
@item @code{ignore-missing?} (default: @code{#f})
Whether to ignore missing battery errors.
@end table
@end deftp
@node Shepherd Home Service
@subsection Managing User Daemons

145
gnu/home/services/pm.scm Normal file
View file

@ -0,0 +1,145 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 ( <paren@disroot.org>
;;;
;;; 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 home services pm)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
#:use-module (gnu packages monitoring)
#:use-module (gnu services shepherd)
#:export (home-batsignal-configuration
home-batsignal-service-type))
;;;
;;; batsignal
;;;
;;; Daemon for running commands and displaying notifications on
;;; battery events.
;;;
(define-record-type* <home-batsignal-configuration>
home-batsignal-configuration make-home-batsignal-configuration
home-batsignal-configuration?
(warning-level batsignal-warning-level ;integer
(default 15))
(warning-message batsignal-warning-message ;string | #f
(default #f))
(critical-level batsignal-critical-level ;integer
(default 5))
(critical-message batsignal-critical-message ;string | #f
(default #f))
(danger-level batsignal-danger-level ;integer
(default 2))
(danger-command batsignal-danger-command ;file-like | string | #f
(default #f))
(full-level batsignal-full-level ;integer | #f
(default #f))
(full-message batsignal-full-message ;string | #f
(default #f))
(batteries batsignal-batteries ;list of string
(default '()))
(poll-delay batsignal-poll-delay ;integer
(default 60))
(icon batsignal-icon ;file-like | #f
(default #f))
(notifications? batsignal-notifications? ;boolean
(default #t))
(notifications-expire? batsignal-notifications-expire? ;boolean
(default #f))
(notification-command batsignal-notification-command ;string | #f
(default #f))
(ignore-missing? batsignal-ignore-missing? ;boolean
(default #f)))
(define (home-batsignal-shepherd-services config)
(let ((warning-level (batsignal-warning-level config))
(warning-message (batsignal-warning-message config))
(critical-level (batsignal-critical-level config))
(critical-message (batsignal-critical-message config))
(danger-level (batsignal-danger-level config))
(danger-command (batsignal-danger-command config))
(full-level (batsignal-full-level config))
(full-message (batsignal-full-message config))
(batteries (batsignal-batteries config))
(poll-delay (batsignal-poll-delay config))
(icon (batsignal-icon config))
(notifications? (batsignal-notifications? config))
(notifications-expire? (batsignal-notifications-expire? config))
(notification-command (batsignal-notification-command config))
(ignore-missing? (batsignal-ignore-missing? config)))
(list (shepherd-service
(provision '(batsignal))
(documentation "Run the batsignal battery-watching daemon.")
(start #~(make-forkexec-constructor
(append (list #$(file-append batsignal "/bin/batsignal")
"-w" (number->string #$warning-level)
"-c" (number->string #$critical-level)
"-d" (number->string #$danger-level)
"-m" (number->string #$poll-delay))
(if #$warning-message
(list "-W" #$warning-message)
(list))
(if #$critical-message
(list "-C" #$critical-message)
(list))
(if #$danger-command
(list "-D" #$danger-command)
(list))
(if #$full-level
(list "-f" (number->string #$full-level))
(list))
(if #$full-message
(list "-F" #$full-message)
(list))
(if (null? (list #$@batteries))
(list)
(list "-n" (string-join (list #$@batteries) ",")))
(if #$icon
(list "-I" #$icon)
(list))
(if #$notifications?
(list)
(list "-N"))
(if #$notifications-expire?
(list "-e")
(list))
(if #$notification-command
(list "-M" #$notification-command)
(list))
(if #$ignore-missing?
(list "-i")
(list)))
#:log-file (string-append
(or (getenv "XDG_LOG_HOME")
(format #f "~a/.local/var/log"
(getenv "HOME")))
"/batsignal.log")))
(stop #~(make-kill-destructor))))))
(define home-batsignal-service-type
(service-type
(name 'home-batsignal)
(extensions
(list (service-extension home-shepherd-service-type
home-batsignal-shepherd-services)))
(default-value (home-batsignal-configuration))
(description
"Run batsignal, a battery watching and notification daemon.")))

View file

@ -54,6 +54,7 @@
# Copyright © 2022 muradm <mail@muradm.net>
# Copyright © 2022 Hilton Chain <hako@ultrarare.space>
# Copyright © 2022 Alex Griffin <a@ajgrf.com>
# Copyright © 2022 ( <paren@disroot.org>
#
# This file is part of GNU Guix.
#
@ -89,6 +90,7 @@ GNU_SYSTEM_MODULES = \
%D%/home/services/symlink-manager.scm \
%D%/home/services/fontutils.scm \
%D%/home/services/guix.scm \
%D%/home/services/pm.scm \
%D%/home/services/shells.scm \
%D%/home/services/shepherd.scm \
%D%/home/services/ssh.scm \