| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 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 | |
| 33 | |
| 34 | |
| 35 | |
| 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 |
| 42 | (default 15))
|
| 43 | (warning-message batsignal-warning-message |
| 44 | (default #f))
|
| 45 | (critical-level batsignal-critical-level |
| 46 | (default 5))
|
| 47 | (critical-message batsignal-critical-message |
| 48 | (default #f))
|
| 49 | (danger-level batsignal-danger-level |
| 50 | (default 2))
|
| 51 | (danger-command batsignal-danger-command |
| 52 | (default #f))
|
| 53 | (full-level batsignal-full-level |
| 54 | (default #f))
|
| 55 | (full-message batsignal-full-message |
| 56 | (default #f))
|
| 57 | (batteries batsignal-batteries |
| 58 | (default '()))
|
| 59 | (poll-delay batsignal-poll-delay |
| 60 | (default 60))
|
| 61 | (icon batsignal-icon |
| 62 | (default #f))
|
| 63 | (notifications? batsignal-notifications? |
| 64 | (default #t))
|
| 65 | (notifications-expire? batsignal-notifications-expire? |
| 66 | (default #f))
|
| 67 | (notification-command batsignal-notification-command |
| 68 | (default #f))
|
| 69 | (ignore-missing? batsignal-ignore-missing? |
| 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))) |
| 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.")))
|