pm.scm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. (define-module (gnu home services pm)
  19. #:use-module (guix gexp)
  20. #:use-module (guix packages)
  21. #:use-module (guix records)
  22. #:use-module (gnu home services)
  23. #:use-module (gnu home services shepherd)
  24. #:use-module (gnu packages monitoring)
  25. #:use-module (gnu services shepherd)
  26. #:export (home-batsignal-configuration
  27. home-batsignal-service-type))
  28. ;;;
  29. ;;; batsignal
  30. ;;;
  31. ;;; Daemon for running commands and displaying notifications on
  32. ;;; battery events.
  33. ;;;
  34. (define-record-type* <home-batsignal-configuration>
  35. home-batsignal-configuration make-home-batsignal-configuration
  36. home-batsignal-configuration?
  37. (warning-level batsignal-warning-level ;integer
  38. (default 15))
  39. (warning-message batsignal-warning-message ;string | #f
  40. (default #f))
  41. (critical-level batsignal-critical-level ;integer
  42. (default 5))
  43. (critical-message batsignal-critical-message ;string | #f
  44. (default #f))
  45. (danger-level batsignal-danger-level ;integer
  46. (default 2))
  47. (danger-command batsignal-danger-command ;file-like | string | #f
  48. (default #f))
  49. (full-level batsignal-full-level ;integer | #f
  50. (default #f))
  51. (full-message batsignal-full-message ;string | #f
  52. (default #f))
  53. (batteries batsignal-batteries ;list of string
  54. (default '()))
  55. (poll-delay batsignal-poll-delay ;integer
  56. (default 60))
  57. (icon batsignal-icon ;file-like | #f
  58. (default #f))
  59. (notifications? batsignal-notifications? ;boolean
  60. (default #t))
  61. (notifications-expire? batsignal-notifications-expire? ;boolean
  62. (default #f))
  63. (notification-command batsignal-notification-command ;string | #f
  64. (default #f))
  65. (ignore-missing? batsignal-ignore-missing? ;boolean
  66. (default #f)))
  67. (define (home-batsignal-shepherd-services config)
  68. (let ((warning-level (batsignal-warning-level config))
  69. (warning-message (batsignal-warning-message config))
  70. (critical-level (batsignal-critical-level config))
  71. (critical-message (batsignal-critical-message config))
  72. (danger-level (batsignal-danger-level config))
  73. (danger-command (batsignal-danger-command config))
  74. (full-level (batsignal-full-level config))
  75. (full-message (batsignal-full-message config))
  76. (batteries (batsignal-batteries config))
  77. (poll-delay (batsignal-poll-delay config))
  78. (icon (batsignal-icon config))
  79. (notifications? (batsignal-notifications? config))
  80. (notifications-expire? (batsignal-notifications-expire? config))
  81. (notification-command (batsignal-notification-command config))
  82. (ignore-missing? (batsignal-ignore-missing? config)))
  83. (list (shepherd-service
  84. (provision '(batsignal))
  85. (documentation "Run the batsignal battery-watching daemon.")
  86. (start #~(make-forkexec-constructor
  87. (append (list #$(file-append batsignal "/bin/batsignal")
  88. "-w" (number->string #$warning-level)
  89. "-c" (number->string #$critical-level)
  90. "-d" (number->string #$danger-level)
  91. "-m" (number->string #$poll-delay))
  92. (if #$warning-message
  93. (list "-W" #$warning-message)
  94. (list))
  95. (if #$critical-message
  96. (list "-C" #$critical-message)
  97. (list))
  98. (if #$danger-command
  99. (list "-D" #$danger-command)
  100. (list))
  101. (if #$full-level
  102. (list "-f" (number->string #$full-level))
  103. (list))
  104. (if #$full-message
  105. (list "-F" #$full-message)
  106. (list))
  107. (if (null? (list #$@batteries))
  108. (list)
  109. (list "-n" (string-join (list #$@batteries) ",")))
  110. (if #$icon
  111. (list "-I" #$icon)
  112. (list))
  113. (if #$notifications?
  114. (list)
  115. (list "-N"))
  116. (if #$notifications-expire?
  117. (list "-e")
  118. (list))
  119. (if #$notification-command
  120. (list "-M" #$notification-command)
  121. (list))
  122. (if #$ignore-missing?
  123. (list "-i")
  124. (list)))
  125. #:log-file (string-append
  126. (or (getenv "XDG_LOG_HOME")
  127. (format #f "~a/.local/var/log"
  128. (getenv "HOME")))
  129. "/batsignal.log")))
  130. (stop #~(make-kill-destructor))))))
  131. (define home-batsignal-service-type
  132. (service-type
  133. (name 'home-batsignal)
  134. (extensions
  135. (list (service-extension home-shepherd-service-type
  136. home-batsignal-shepherd-services)))
  137. (default-value (home-batsignal-configuration))
  138. (description
  139. "Run batsignal, a battery watching and notification daemon.")))