From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gPyMFPTWNWO0GAAAbAwnHQ (envelope-from ) for ; Thu, 29 Sep 2022 19:33:40 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id CCiPE/TWNWO0kwAAG6o9tA (envelope-from ) for ; Thu, 29 Sep 2022 19:33:40 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0560A2E3FC for ; Thu, 29 Sep 2022 19:33:40 +0200 (CEST) Received: from localhost ([::1]:32936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odxPn-0000TA-1h for larch@yhetil.org; Thu, 29 Sep 2022 13:33:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odwat-0005A0-Si for guix-patches@gnu.org; Thu, 29 Sep 2022 12:41:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odwat-0004us-6B for guix-patches@gnu.org; Thu, 29 Sep 2022 12:41:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1odwas-00029b-Vv for guix-patches@gnu.org; Thu, 29 Sep 2022 12:41:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58170] [PATCH 1/1] gnu: home: Add home-batsignal-service-type. References: <20220929163853.9019-1-paren@disroot.org> In-Reply-To: <20220929163853.9019-1-paren@disroot.org> Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 29 Sep 2022 16:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58170 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58170@debbugs.gnu.org Cc: "\(" Received: via spool by 58170-submit@debbugs.gnu.org id=B58170.16644696288200 (code B ref 58170); Thu, 29 Sep 2022 16:41:02 +0000 Received: (at 58170) by debbugs.gnu.org; 29 Sep 2022 16:40:28 +0000 Received: from localhost ([127.0.0.1]:39408 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odwaJ-00028B-Dj for submit@debbugs.gnu.org; Thu, 29 Sep 2022 12:40:28 -0400 Received: from knopi.disroot.org ([178.21.23.139]:38670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odwaH-00027y-4W for 58170@debbugs.gnu.org; Thu, 29 Sep 2022 12:40:26 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 76FC54BFD1; Thu, 29 Sep 2022 18:40:24 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cIP0-QuwmJks; Thu, 29 Sep 2022 18:40:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1664469622; bh=XgwRzkW6hRM6azmGmAhrUcPC3yRdr0GAX7gdtvR3QH8=; h=From:To:Cc:Subject:Date; b=l6GTQ65KxYyy7aFoVDm7KXcZV5a9A4hEhqttNfQI9e2XRTotI0HKDUAqeZAKT3om4 wb+6kn12WfuQVSOZ3co7ItP4i/BKkgStUaprLt2N6hLKXuJRxo837/rdowhS+oqUa5 pscUibdU/pWQ273BdVR3kd4a6nfpKZCXq1pAYiepBz+1UKNcIxpoI4UMdI1MMQjDcw vESGobzMUMHoOQf1pwoB4xa3jFFW0OAL+Z7i2s9sC+CRFJEsh00AlHS+S5DsHfTujB rIpR1igCHJvp7q159f4j0Nu/yy1PejRLi8qpAWGZZCZf3b6i/rb/M+fqUkimOFVC3D j1awvUNJcMz4w== Date: Thu, 29 Sep 2022 17:40:20 +0100 Message-Id: <20220929164020.9178-1-paren@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664472820; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=bziU1uHuLfC1Trxe5/efd5lG4F/OWwLjmhArfxXaQqs=; b=ALB1uonGB0HNueNhp8ois7E3GVyV/BP6zNxickM2kpcdSWsfkXBFj/RWFKoPIF796kGsYA cX1yqUxj0yHyRoR8+WIF+SkaRKInOTcp01cKQayMugXnludkVwgh5FN9OIoTgI50tx9Gsx Y+ow9FKNZjX8oYPyyEXdjU8pvHD+19vnxrE3PQCHUb6M35Vv5l1VYTtgxDJDiNlGjoZPdt 0bKOQo2xVcysnNPT8lA6FbDP2EBb6co50WYyp0Z611Mi/PRr6s10ExbQYsqhMcF3G1kl8e ilccBqEwi/JVAcI3CMKpM1MmOqh3q3+oFMnPx4RYwt0scChF1VQiPieCU2EFtw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664472820; a=rsa-sha256; cv=none; b=bayXn6J00eAty0PgfwhCx4nbjgdlRWsUncWvQvZ5WJcLzC/i5ZToAI/KOCi7FXIxYNEQCb t26TgAwI/eip8YcofXFDd/bmQTKBFtHwZIWw/6En6Ta2kxs7ng/9kzWFr/9JhdVlAciGmw HL8AOc8V2TWrnzUuTv7sEGCsXZJEsJCezw5WeaMhzh+z+d209dIYuA8MMph8I+OEq+9FPM zXxtn13URiQCbtl+0mdj04O1s3shQq5Zo3GfVTENf21BWZnJCRs80XoqIWZnmcHE0WlTW0 m/K9a6RufBV4mdKydpGZ8XvCZs0AfZrs/2tZu6zGp4dP26Kib0+lXP8rVYXGXw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=l6GTQ65K; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.14 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=l6GTQ65K; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 0560A2E3FC X-Spam-Score: -2.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: d675VeMsXLB4 * 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. --- doc/guix.texi | 89 ++++++++++++++++++++++-- gnu/home/services/pm.scm | 145 +++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 2 + 3 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 gnu/home/services/pm.scm diff --git a/doc/guix.texi b/doc/guix.texi index c534574f81..081a7fb34f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -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 @@ -40119,12 +40120,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 @@ -40572,6 +40574,81 @@ specifications,, mcron, GNU@tie{}mcron}). @end table @end deftp +@node 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 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 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 ( +;;; +;;; 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 . + +(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 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."))) diff --git a/gnu/local.mk b/gnu/local.mk index 4e982dc6e3..9ef10fcbfe 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -54,6 +54,7 @@ # Copyright © 2022 muradm # Copyright © 2022 Hilton Chain # Copyright © 2022 Alex Griffin +# Copyright © 2022 ( # # 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 \ -- 2.37.3