summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author( via Guix-patches via <guix-patches@gnu.org>2022-09-29 17:40:20 +0100
committerAndrew Tropin <andrew@trop.in>2022-10-04 17:04:45 +0400
commit7030f592c643360105514f9f1f923b0b6342d5e3 (patch)
tree609a55d5f28da4b666877ee63d0522a2d2488bee
parentdoc: Mention network mask in network-route. (diff)
downloadguix-7030f592c643360105514f9f1f923b0b6342d5e3.tar.gz
guix-7030f592c643360105514f9f1f923b0b6342d5e3.tar.bz2
guix-7030f592c643360105514f9f1f923b0b6342d5e3.tar.xz
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.
-rw-r--r--doc/guix.texi90
-rw-r--r--gnu/home/services/pm.scm145
-rw-r--r--gnu/local.mk2
3 files changed, 231 insertions, 6 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index fb9efe6b4f..eeec4dec2c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -107,6 +107,7 @@ Copyright @copyright{} 2022 Karl Hallsby@*
107Copyright @copyright{} 2022 Justin Veilleux@* 107Copyright @copyright{} 2022 Justin Veilleux@*
108Copyright @copyright{} 2022 Reily Siegel@* 108Copyright @copyright{} 2022 Reily Siegel@*
109Copyright @copyright{} 2022 Simon Streit@* 109Copyright @copyright{} 2022 Simon Streit@*
110Copyright @copyright{} 2022 (@*
110 111
111Permission is granted to copy, distribute and/or modify this document 112Permission is granted to copy, distribute and/or modify this document
112under the terms of the GNU Free Documentation License, Version 1.3 or 113under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -40154,12 +40155,13 @@ services)}.
40154 40155
40155@menu 40156@menu
40156* Essential Home Services:: Environment variables, packages, on-* scripts. 40157* Essential Home Services:: Environment variables, packages, on-* scripts.
40157* Shells: Shells Home Services. POSIX shells, Bash, Zsh. 40158* Shells: Shells Home Services. POSIX shells, Bash, Zsh.
40158* Mcron: Mcron Home Service. Scheduled User's Job Execution. 40159* Mcron: Mcron Home Service. Scheduled User's Job Execution.
40159* Shepherd: Shepherd Home Service. Managing User's Daemons. 40160* Power Management: Power Management Home Services. Services for battery power.
40160* SSH: Secure Shell. Setting up the secure shell client. 40161* Shepherd: Shepherd Home Service. Managing User's Daemons.
40161* Desktop: Desktop Home Services. Services for graphical environments. 40162* SSH: Secure Shell. Setting up the secure shell client.
40162* Guix: Guix Home Services. Services for Guix. 40163* Desktop: Desktop Home Services. Services for graphical environments.
40164* Guix: Guix Home Services. Services for Guix.
40163@end menu 40165@end menu
40164@c In addition to that Home Services can provide 40166@c In addition to that Home Services can provide
40165 40167
@@ -40607,6 +40609,82 @@ specifications,, mcron, GNU@tie{}mcron}).
40607@end table 40609@end table
40608@end deftp 40610@end deftp
40609 40611
40612@node Power Management Home Services
40613@subsection Power Management Home Services
40614
40615@cindex power management
40616The @code{(gnu home services pm)} module provides home services
40617pertaining to battery power.
40618
40619@defvr {Scheme Variable} home-batsignal-service-type
40620Service for @code{batsignal}, a program that monitors battery levels
40621and warns the user through desktop notifications when their battery
40622is getting low. You can also configure a command to be run when the
40623battery level passes a point deemed ``dangerous''. This service is
40624configured with the @code{home-batsignal-configuration} record.
40625@end defvr
40626
40627@deftp {Data Type} home-batsignal-configuration
40628Data type representing the configuration for batsignal.
40629
40630@table @asis
40631@item @code{warning-level} (default: @code{15})
40632The battery level to send a warning message at.
40633
40634@item @code{warning-message} (default: @code{#f})
40635The message to send as a notification when the battery level reaches
40636the @code{warning-level}. Setting to @code{#f} uses the default
40637message.
40638
40639@item @code{critical-level} (default: @code{5})
40640The battery level to send a critical message at.
40641
40642@item @code{critical-message} (default: @code{#f})
40643The message to send as a notification when the battery level reaches
40644the @code{critical-level}. Setting to @code{#f} uses the default
40645message.
40646
40647@item @code{danger-level} (default: @code{2})
40648The battery level to run the @code{danger-command} at.
40649
40650@item @code{danger-command} (default: @code{#f})
40651The command to run when the battery level reaches the @code{danger-level}.
40652Setting to @code{#f} disables running the command entirely.
40653
40654@item @code{full-level} (default: @code{#f})
40655The battery level to send a full message at. Setting to @code{#f}
40656disables sending the full message entirely.
40657
40658@item @code{full-message} (default: @code{#f})
40659The message to send as a notification when the battery level reaches
40660the @code{full-level}. Setting to @code{#f} uses the default message.
40661
40662@item @code{batteries} (default: @code{'()})
40663The batteries to monitor. Setting to @code{'()} tries to find batteries
40664automatically.
40665
40666@item @code{poll-delay} (default: @code{60})
40667The time in seconds to wait before checking the batteries again.
40668
40669@item @code{icon} (default: @code{#f})
40670A file-like object to use as the icon for battery notifications. Setting
40671to @code{#f} disables notification icons entirely.
40672
40673@item @code{notifications?} (default: @code{#t})
40674Whether to send any notifications.
40675
40676@item @code{notifications-expire?} (default: @code{#f})
40677Whether notifications sent expire after a time.
40678
40679@item @code{notification-command} (default: @code{#f})
40680Command to use to send messages. Setting to @code{#f} sends a notification
40681through @code{libnotify}.
40682
40683@item @code{ignore-missing?} (default: @code{#f})
40684Whether to ignore missing battery errors.
40685@end table
40686@end deftp
40687
40610@node Shepherd Home Service 40688@node Shepherd Home Service
40611@subsection Managing User Daemons 40689@subsection Managing User Daemons
40612 40690
diff --git a/gnu/home/services/pm.scm b/gnu/home/services/pm.scm
new file mode 100644
index 0000000000..5f09941827
--- /dev/null
+++ b/gnu/home/services/pm.scm
@@ -0,0 +1,145 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2022 ( <paren@disroot.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation, either version 3 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu home services pm)
20 #:use-module (guix gexp)
21 #:use-module (guix packages)
22 #:use-module (guix records)
23 #:use-module (gnu home services)
24 #:use-module (gnu home services shepherd)
25 #:use-module (gnu packages monitoring)
26 #:use-module (gnu services shepherd)
27
28 #:export (home-batsignal-configuration
29 home-batsignal-service-type))
30
31;;;
32;;; batsignal
33;;;
34;;; Daemon for running commands and displaying notifications on
35;;; battery events.
36;;;
37
38(define-record-type* <home-batsignal-configuration>
39 home-batsignal-configuration make-home-batsignal-configuration
40 home-batsignal-configuration?
41 (warning-level batsignal-warning-level ;integer
42 (default 15))
43 (warning-message batsignal-warning-message ;string | #f
44 (default #f))
45 (critical-level batsignal-critical-level ;integer
46 (default 5))
47 (critical-message batsignal-critical-message ;string | #f
48 (default #f))
49 (danger-level batsignal-danger-level ;integer
50 (default 2))
51 (danger-command batsignal-danger-command ;file-like | string | #f
52 (default #f))
53 (full-level batsignal-full-level ;integer | #f
54 (default #f))
55 (full-message batsignal-full-message ;string | #f
56 (default #f))
57 (batteries batsignal-batteries ;list of string
58 (default '()))
59 (poll-delay batsignal-poll-delay ;integer
60 (default 60))
61 (icon batsignal-icon ;file-like | #f
62 (default #f))
63 (notifications? batsignal-notifications? ;boolean
64 (default #t))
65 (notifications-expire? batsignal-notifications-expire? ;boolean
66 (default #f))
67 (notification-command batsignal-notification-command ;string | #f
68 (default #f))
69 (ignore-missing? batsignal-ignore-missing? ;boolean
70 (default #f)))
71
72(define (home-batsignal-shepherd-services config)
73 (let ((warning-level (batsignal-warning-level config))
74 (warning-message (batsignal-warning-message config))
75 (critical-level (batsignal-critical-level config))
76 (critical-message (batsignal-critical-message config))
77 (danger-level (batsignal-danger-level config))
78 (danger-command (batsignal-danger-command config))
79 (full-level (batsignal-full-level config))
80 (full-message (batsignal-full-message config))
81 (batteries (batsignal-batteries config))
82 (poll-delay (batsignal-poll-delay config))
83 (icon (batsignal-icon config))
84 (notifications? (batsignal-notifications? config))
85 (notifications-expire? (batsignal-notifications-expire? config))
86 (notification-command (batsignal-notification-command config))
87 (ignore-missing? (batsignal-ignore-missing? config)))
88 (list (shepherd-service
89 (provision '(batsignal))
90 (documentation "Run the batsignal battery-watching daemon.")
91 (start #~(make-forkexec-constructor
92 (append (list #$(file-append batsignal "/bin/batsignal")
93 "-w" (number->string #$warning-level)
94 "-c" (number->string #$critical-level)
95 "-d" (number->string #$danger-level)
96 "-m" (number->string #$poll-delay))
97 (if #$warning-message
98 (list "-W" #$warning-message)
99 (list))
100 (if #$critical-message
101 (list "-C" #$critical-message)
102 (list))
103 (if #$danger-command
104 (list "-D" #$danger-command)
105 (list))
106 (if #$full-level
107 (list "-f" (number->string #$full-level))
108 (list))
109 (if #$full-message
110 (list "-F" #$full-message)
111 (list))
112 (if (null? (list #$@batteries))
113 (list)
114 (list "-n" (string-join (list #$@batteries) ",")))
115 (if #$icon
116 (list "-I" #$icon)
117 (list))
118 (if #$notifications?
119 (list)
120 (list "-N"))
121 (if #$notifications-expire?
122 (list "-e")
123 (list))
124 (if #$notification-command
125 (list "-M" #$notification-command)
126 (list))
127 (if #$ignore-missing?
128 (list "-i")
129 (list)))
130 #:log-file (string-append
131 (or (getenv "XDG_LOG_HOME")
132 (format #f "~a/.local/var/log"
133 (getenv "HOME")))
134 "/batsignal.log")))
135 (stop #~(make-kill-destructor))))))
136
137(define home-batsignal-service-type
138 (service-type
139 (name 'home-batsignal)
140 (extensions
141 (list (service-extension home-shepherd-service-type
142 home-batsignal-shepherd-services)))
143 (default-value (home-batsignal-configuration))
144 (description
145 "Run batsignal, a battery watching and notification daemon.")))
diff --git a/gnu/local.mk b/gnu/local.mk
index e9178923af..5976cbe90c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -54,6 +54,7 @@
54# Copyright © 2022 muradm <mail@muradm.net> 54# Copyright © 2022 muradm <mail@muradm.net>
55# Copyright © 2022 Hilton Chain <hako@ultrarare.space> 55# Copyright © 2022 Hilton Chain <hako@ultrarare.space>
56# Copyright © 2022 Alex Griffin <a@ajgrf.com> 56# Copyright © 2022 Alex Griffin <a@ajgrf.com>
57# Copyright © 2022 ( <paren@disroot.org>
57# 58#
58# This file is part of GNU Guix. 59# This file is part of GNU Guix.
59# 60#
@@ -89,6 +90,7 @@ GNU_SYSTEM_MODULES = \
89 %D%/home/services/symlink-manager.scm \ 90 %D%/home/services/symlink-manager.scm \
90 %D%/home/services/fontutils.scm \ 91 %D%/home/services/fontutils.scm \
91 %D%/home/services/guix.scm \ 92 %D%/home/services/guix.scm \
93 %D%/home/services/pm.scm \
92 %D%/home/services/shells.scm \ 94 %D%/home/services/shells.scm \
93 %D%/home/services/shepherd.scm \ 95 %D%/home/services/shepherd.scm \
94 %D%/home/services/ssh.scm \ 96 %D%/home/services/ssh.scm \