projects/guix·blob python-team · refs

143 lines · 6.5 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2022 ( <[email protected]>
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 (modules '((shepherd support))) ;for '%user-log-dir'
92 (start #~(make-forkexec-constructor
93 (append (list #$(file-append batsignal "/bin/batsignal")
94 "-w" (number->string #$warning-level)
95 "-c" (number->string #$critical-level)
96 "-d" (number->string #$danger-level)
97 "-m" (number->string #$poll-delay))
98 (if #$warning-message
99 (list "-W" #$warning-message)
100 (list))
101 (if #$critical-message
102 (list "-C" #$critical-message)
103 (list))
104 (if #$danger-command
105 (list "-D" #$danger-command)
106 (list))
107 (if #$full-level
108 (list "-f" (number->string #$full-level))
109 (list))
110 (if #$full-message
111 (list "-F" #$full-message)
112 (list))
113 (if (null? (list #$@batteries))
114 (list)
115 (list "-n" (string-join (list #$@batteries) ",")))
116 (if #$icon
117 (list "-I" #$icon)
118 (list))
119 (if #$notifications?
120 (list)
121 (list "-N"))
122 (if #$notifications-expire?
123 (list "-e")
124 (list))
125 (if #$notification-command
126 (list "-M" #$notification-command)
127 (list))
128 (if #$ignore-missing?
129 (list "-i")
130 (list)))
131 #:log-file
132 (string-append %user-log-dir "/batsignal.log")))
133 (stop #~(make-kill-destructor))))))
134
135(define home-batsignal-service-type
136 (service-type
137 (name 'home-batsignal)
138 (extensions
139 (list (service-extension home-shepherd-service-type
140 home-batsignal-shepherd-services)))
141 (default-value (home-batsignal-configuration))
142 (description
143 "Run batsignal, a battery watching and notification daemon.")))