unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: 45mg <45mg.writes@gmail.com>
To: 74819@debbugs.gnu.org
Cc: 45mg <45mg.writes@gmail.com>
Subject: [bug#74819] [PATCH v3] services: elogind: Support Hook Directories
Date: Wed, 18 Dec 2024 07:18:49 -0500	[thread overview]
Message-ID: <1688c8ebd2c7d074edce3b27c0e439c5897ee251.1734524329.git.45mg.writes@gmail.com> (raw)
In-Reply-To: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com>

Allow the user to specify scripts to be added into Elogind's hook
directories. These scripts will be run before/after
suspend/hibernate/poweroff/reboot.

Also allow setting the associated config options.

* gnu/services/desktop.scm (elogind-configuration): add
`system-sleep-hook-files`, `system-shutdown-hook-files`,
and 4 new config options.
(elogind-configuration-file): Add entries for the new config options
under the `[Sleep]` section.
(/etc/elogind): New function, to generate /etc/elogind directory.
(elogind-service-type): Extend `etc-service-type` using `/etc/elogind`.
* doc/guix.texi: Document the new options.

Change-Id: I7e22cbaa9d031049b9d085ba0ce4cc8a8b4f16ff
---
This revision fixes a typo in doc/guix.texi.

Also, I guess I should have CC'ed the mentors team from the start. Doing
that here.

 doc/guix.texi            | 27 +++++++++++++++++++++
 gnu/services/desktop.scm | 51 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index a2915de954..e6f1edadbf 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -134,6 +134,7 @@
 Copyright @copyright{} 2024 Nigko Yerden@*
 Copyright @copyright{} 2024 Troy Figiel@*
 Copyright @copyright{} 2024 Sharlatan Hellseher@*
+Copyright @copyright{} 2024 45mg@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -25282,6 +25283,32 @@ Desktop Services
 @item @code{suspend-estimation-seconds} (default: @code{*unspecified*}) (type: integer)
 ...
 
+@item @code{system-sleep-hook-files} (default: @code{'()}) (type: list)
+A list of executables (file-like objects) that will be installed into
+the @file{/etc/elogind/system-sleep/} hook directory. For example:
+
+@lisp
+(elogind-configuration
+ (system-sleep-hook-files
+  (list (local-file "sleep-script"))))
+@end lisp
+
+See `Hook directories' in the @code{loginctl(1)} man page for more information.
+
+@item @code{system-shutdown-hook-files} (default: @code{'()}) (type: list)
+A list of executables (file-like objects) that will be installed into
+the @file{/etc/elogind/system-shutdown/} hook directory.
+
+@item @code{allow-power-off-interrupts?} (default: @code{#f}) (type: boolean)
+@item @code{allow-suspend-interrupts?} (default: @code{#f}) (type: boolean)
+Whether the executables in Elogind's hook directories (see above) can
+cause a power-off or suspend action to be cancelled (interrupted) by
+printing an appropriate error message to stdout.
+
+@item @code{broadcast-power-off-interrupts?} (default: @code{#t}) (type: boolean)
+@item @code{broadcast-suspend-interrupts?} (default: @code{#t}) (type: boolean)
+Whether an interrupt of a power-off or suspend action is broadcasted.
+
 @end table
 @end deftp
 
diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm
index 274aeeef9b..9614ee8aea 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2021, 2022 muradm <mail@muradm.net>
 ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
 ;;; Copyright © 2023 Zheng Junjie <873216071@qq.com>
+;;; Copyright © 2024 45mg <45mg.writes@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1084,7 +1085,19 @@ (define-record-type* <elogind-configuration> elogind-configuration
   (hibernate-delay-seconds          elogind-hibernate-delay-seconds
                                     (default *unspecified*))
   (suspend-estimation-seconds       elogind-suspend-estimation-seconds
-                                    (default *unspecified*)))
+                                    (default *unspecified*))
+  (system-sleep-hook-files          elogind-system-sleep-hook-files
+                                    (default '()))
+  (system-shutdown-hook-files       elogind-system-shutdown-hook-files
+                                    (default '()))
+  (allow-power-off-interrupts?      elogind-allow-power-off-interrupts?
+                                    (default #f))
+  (allow-suspend-interrupts?        elogind-allow-suspend-interrupts?
+                                    (default #f))
+  (broadcast-power-off-interrupts?  elogind-broadcast-power-off-interrupts?
+                                    (default #t))
+  (broadcast-suspend-interrupts?    elogind-broadcast-suspend-interrupts?
+                                    (default #t)))
 
 (define (elogind-configuration-file config)
   (define (yesno x)
@@ -1172,7 +1185,35 @@ (define (elogind-configuration-file config)
    ("HybridSleepState" (sleep-list elogind-hybrid-sleep-state))
    ("HybridSleepMode" (sleep-list elogind-hybrid-sleep-mode))
    ("HibernateDelaySec" (maybe-non-negative-integer elogind-hibernate-delay-seconds))
-   ("SuspendEstimationSec" (maybe-non-negative-integer elogind-suspend-estimation-seconds))))
+   ("SuspendEstimationSec" (maybe-non-negative-integer elogind-suspend-estimation-seconds))
+   ("AllowPowerOffInterrupts" (yesno elogind-allow-power-off-interrupts?))
+   ("AllowSuspendInterrupts" (yesno elogind-allow-suspend-interrupts?))
+   ("BroadcastPowerOffInterrupts" (yesno elogind-broadcast-power-off-interrupts?))
+   ("BroadcastSuspendInterrupts" (yesno elogind-broadcast-suspend-interrupts?))))
+
+(define (/etc/elogind config)
+  "Return the /etc/elogind directory for CONFIG."
+  (with-imported-modules (source-module-closure '((guix build utils)))
+    (computed-file
+     "etc-elogind"
+
+     #~(let ((sleep-dir (string-append #$output "/system-sleep/"))
+             (shutdown-dir (string-append #$output "/system-shutdown/")))
+         (use-modules (guix build utils))
+
+         (define (copy-script file dir)
+           "Copy FILE into DIR, giving rx (500) permissions."
+           (let ((dest (string-append dir "/" (basename file))))
+             (mkdir-p dir)
+             (copy-file file dest)
+             (chmod dest #o500)))
+
+         (for-each
+          (lambda (f) (copy-script f sleep-dir))
+          '#$(elogind-system-sleep-hook-files config))
+         (for-each
+          (lambda (f) (copy-script f shutdown-dir))
+          '#$(elogind-system-shutdown-hook-files config))))))
 
 (define (elogind-dbus-service config)
   "Return a @file{org.freedesktop.login1.service} file that tells D-Bus how to
@@ -1294,6 +1335,12 @@ (define elogind-service-type
                        (service-extension pam-root-service-type
                                           pam-extension-procedure)
 
+                       ;; Install sleep/shutdown hook files.
+                       (service-extension etc-service-type
+                                          (lambda (config)
+                                            `(("elogind" ,(/etc/elogind config)))))
+
+
                        ;; We need /run/user, /run/systemd, etc.
                        (service-extension file-system-service-type
                                           (const %elogind-file-systems))))

base-commit: d916d3b1568a2def0dfb9089d61f2202db35beb7
-- 
2.46.0





  parent reply	other threads:[~2024-12-18 12:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12 11:33 [bug#74819] [PATCH] services: elogind: Support Hook Directories 45mg
2024-12-12 13:00 ` 45mg
2024-12-16  6:26 ` [bug#74819] [PATCH v2] " 45mg
2024-12-16  6:37   ` 45mg
2024-12-18 12:18 ` 45mg [this message]
2024-12-23 18:00   ` [bug#74819] [PATCH v3] " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1688c8ebd2c7d074edce3b27c0e439c5897ee251.1734524329.git.45mg.writes@gmail.com \
    --to=45mg.writes@gmail.com \
    --cc=74819@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).