Package: guix-patches;
Reported by: 45mg <45mg.writes <at> gmail.com>
Date: Thu, 12 Dec 2024 11:35:01 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 74819 in the body.
You can then email your comments to 74819 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Thu, 12 Dec 2024 11:35:02 GMT) Full text and rfc822 format available.45mg <45mg.writes <at> gmail.com>
:ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
.
(Thu, 12 Dec 2024 11:35:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: guix-patches <at> gnu.org Cc: 45mg <45mg.writes <at> gmail.com> Subject: [PATCH] services: elogind: Support Hook Directories Date: Thu, 12 Dec 2024 11:33:46 +0000
Allow the user to specify scripts to be added into Elogind's hook directories. This gives users a way to run scripts before/after suspend/hibernate/poweroff/reboot. Also allow setting the related sleep config options. * gnu/services/desktop.scm (elogind-configuration): add `system-sleep-hook-files`, `system-shutdown-hook-files`, `allow-power-off-interrupts?`, `allow-suspend-interrupts?`, `broadcast-power-off-interrupts?`, `broadcast-suspend-interrupts?`. (elogind-configuration-file): Add the corresponding entries under the `[Sleep]` section. (elogind-service-type): Extend `activation-service-type` with new `elogind-activation`. (elogind-activation): Copy the supplied script files into the hook directories. * doc/guix.texi: Document the new options. Change-Id: I7e22cbaa9d031049b9d085ba0ce4cc8a8b4f16ff --- doc/guix.texi | 27 ++++++++++++++++++++ gnu/services/desktop.scm | 54 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index a2915de954..36977b9bbc 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-shutdown/} hook directory. + +@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..ed644385f5 100644 --- a/gnu/services/desktop.scm +++ b/gnu/services/desktop.scm @@ -17,6 +17,7 @@ ;;; Copyright © 2021, 2022 muradm <mail <at> muradm.net> ;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu> ;;; Copyright © 2023 Zheng Junjie <873216071 <at> qq.com> +;;; Copyright © 2024 45mg <45mg.writes <at> 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,40 @@ (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 (elogind-activation config) + "Return the activation GEXP for CONFIG." + + (with-imported-modules (source-module-closure '((guix build utils))) + #~(let ((sleep-dir "/etc/elogind/system-sleep/") + (shutdown-dir "/etc/elogind/system-shutdown/")) + (use-modules (guix build utils)) + + (define (install-script file dir) + "Copy FILE into DIR, giving executable (700) permissions." + (let ((dest (string-append dir "/" (basename file)))) + (mkdir-p dir) + (copy-file file dest) + (chmod dest #o700))) + + ;; Clear the sleep/shutdown directories + (for-each (lambda (d) + (when (file-exists? d) + (delete-file-recursively d))) + (list sleep-dir shutdown-dir)) + + ;; Copy the files into them + (for-each + (lambda (f) (install-script f sleep-dir)) + '#$(elogind-system-sleep-hook-files config)) + (for-each + (lambda (f) (install-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 +1340,10 @@ (define elogind-service-type (service-extension pam-root-service-type pam-extension-procedure) + ;; Install sleep/shutdown hook files. + (service-extension activation-service-type + elogind-activation) + ;; We need /run/user, /run/systemd, etc. (service-extension file-system-service-type (const %elogind-file-systems)))) base-commit: d916d3b1568a2def0dfb9089d61f2202db35beb7 -- 2.46.0
guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Thu, 12 Dec 2024 13:03:02 GMT) Full text and rfc822 format available.Message #8 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: 74819 <at> debbugs.gnu.org Subject: Re: [PATCH] services: elogind: Support Hook Directories Date: Thu, 12 Dec 2024 08:00:51 -0500
[Message part 1 (text/plain, inline)]
Here's how I tested these changes if anyone is interested: - Add the files included here into a `testdir` directory - Compile guix shell -D guix --pure -- make - Test in a container (no loginctl sessions, but will catch obvious errors) sudo $(./pre-inst-env guix system container path/to/testdir/test-config.scm) - Test in a VM (need --full-boot for the ability to suspend, etc) $(./pre-inst-env guix system vm --full-boot path/to/testdir/test-config.scm)
[test-config.scm (application/octet-stream, inline)]
[test-sleep-script (application/octet-stream, inline)]
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Mon, 16 Dec 2024 06:30:03 GMT) Full text and rfc822 format available.Message #11 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: 74819 <at> debbugs.gnu.org Cc: 45mg <45mg.writes <at> gmail.com> Subject: [PATCH v2] services: elogind: Support Hook Directories Date: Mon, 16 Dec 2024 01:26:50 -0500
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 --- 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..36977b9bbc 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-shutdown/} hook directory. + +@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 <at> muradm.net> ;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu> ;;; Copyright © 2023 Zheng Junjie <873216071 <at> qq.com> +;;; Copyright © 2024 45mg <45mg.writes <at> 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
guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Mon, 16 Dec 2024 06:39:02 GMT) Full text and rfc822 format available.Message #14 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: 45mg <45mg.writes <at> gmail.com>, 74819 <at> debbugs.gnu.org Cc: 45mg <45mg.writes <at> gmail.com> Subject: Re: [PATCH v2] services: elogind: Support Hook Directories Date: Mon, 16 Dec 2024 01:37:19 -0500
This revision extends `etc-service-type` instead of `activation-service-type`, which allows us to avoid duplicating the functionality of the former. (forgot to --annotate the revision, so I'm mentioning it here)
, guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Wed, 18 Dec 2024 12:23:02 GMT) Full text and rfc822 format available.Message #17 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: 74819 <at> debbugs.gnu.org Cc: 45mg <45mg.writes <at> gmail.com> Subject: [PATCH v3] services: elogind: Support Hook Directories Date: Wed, 18 Dec 2024 07:18:49 -0500
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 <at> muradm.net> ;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu> ;;; Copyright © 2023 Zheng Junjie <873216071 <at> qq.com> +;;; Copyright © 2024 45mg <45mg.writes <at> 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
guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Mon, 23 Dec 2024 18:01:03 GMT) Full text and rfc822 format available.Message #20 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: Ludovic Courtès <ludo <at> gnu.org> To: 45mg <45mg.writes <at> gmail.com> Cc: Simon Tournier <zimon.toutoune <at> gmail.com>, paren <at> disroot.org, Tobias Geerinckx-Rice <me <at> tobias.gr>, jgart <jgart <at> dismail.de>, 74819 <at> debbugs.gnu.org, Mathieu Othacehe <othacehe <at> gnu.org>, Christopher Baines <guix <at> cbaines.net> Subject: Re: [bug#74819] [PATCH v3] services: elogind: Support Hook Directories Date: Mon, 23 Dec 2024 19:00:24 +0100
Hi, 45mg <45mg.writes <at> gmail.com> skribis: > 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 Nice! [...] > +@item @code{allow-power-off-interrupts?} (default: @code{#f}) (type: boolean) > +@item @code{allow-suspend-interrupts?} (default: @code{#f}) (type: boolean) Write “@itemx” for the second line: both will show up next to one another. > +Whether the executables in Elogind's hook directories (see above) can I believe “elogind” is usually spelled lower-case. > +@item @code{broadcast-power-off-interrupts?} (default: @code{#t}) (type: boolean) > +@item @code{broadcast-suspend-interrupts?} (default: @code{#t}) (type: boolean) “@itemx” as well. > +(define (/etc/elogind config) By convention, I’d call it ‘elogind-etc-directory’. > + #~(let ((sleep-dir (string-append #$output "/system-sleep/")) > + (shutdown-dir (string-append #$output "/system-shutdown/"))) > + (use-modules (guix build utils)) ‘use-modules’ should always be used at the top level; it’s not guaranteed to work otherwise (it wouldn’t work if the module exports macros, for instance). Also, please avoid abbreviations. So that gives something like: #~(begin (use-modules (guix build utils)) (define sleep-directory (string-append #$output "/system-sleep")) (define shutdown-directory (string-append #$output "/system-shutdown")) …) Apart from these minor issues, the patch looks great to me. Could you send an updated version? Thanks! Ludo’.
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Fri, 27 Dec 2024 12:18:01 GMT) Full text and rfc822 format available.Message #23 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: 74819 <at> debbugs.gnu.org Cc: 45mg <45mg.writes <at> gmail.com> Subject: [PATCH v4] services: elogind: Support Hook Directories Date: Fri, 27 Dec 2024 07:15:02 -0500
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 --- doc/guix.texi | 27 ++++++++++++++++++++ gnu/services/desktop.scm | 54 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 31deb5b003..5324a5f67a 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 @@ -25366,6 +25367,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) +@itemx @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) +@itemx @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 4f679485bc..da96b3bc47 100644 --- a/gnu/services/desktop.scm +++ b/gnu/services/desktop.scm @@ -17,6 +17,7 @@ ;;; Copyright © 2021, 2022 muradm <mail <at> muradm.net> ;;; Copyright © 2023 Bruno Victal <mirai <at> makinata.eu> ;;; Copyright © 2023 Zheng Junjie <873216071 <at> qq.com> +;;; Copyright © 2024 45mg <45mg.writes <at> 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,38 @@ (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 (elogind-etc-directory config) + "Return the /etc/elogind directory for CONFIG." + (with-imported-modules (source-module-closure '((guix build utils))) + (computed-file + "etc-elogind" + + #~(begin + (use-modules (guix build utils)) + + (define sleep-directory (string-append #$output "/system-sleep/")) + (define shutdown-directory (string-append #$output "/system-shutdown/")) + + (define (copy-script file directory) + "Copy FILE into DIRECTORY, giving rx (500) permissions." + (let ((dest (string-append directory "/" (basename file)))) + (mkdir-p directory) + (copy-file file dest) + (chmod dest #o500))) + + (mkdir-p #$output) ; in case neither directory gets created + (for-each + (lambda (f) (copy-script f sleep-directory)) + '#$(elogind-system-sleep-hook-files config)) + (for-each + (lambda (f) (copy-script f shutdown-directory)) + '#$(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 +1338,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" + ,(elogind-etc-directory config))))) + ;; We need /run/user, /run/systemd, etc. (service-extension file-system-service-type (const %elogind-file-systems)))) base-commit: 3ada4796e9adcea6fce621e639ddbfb181ab6689 -- 2.47.1
guix-patches <at> gnu.org
:bug#74819
; Package guix-patches
.
(Sat, 28 Dec 2024 05:48:01 GMT) Full text and rfc822 format available.Message #26 received at 74819 <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: 45mg <45mg.writes <at> gmail.com> Cc: Ludovic Courtès <ludo <at> gnu.org>, 74819 <at> debbugs.gnu.org Subject: Re: [bug#74819] [PATCH v4] services: elogind: Support Hook Directories Date: Sat, 28 Dec 2024 14:46:33 +0900
Hi, 45mg <45mg.writes <at> gmail.com> writes: > 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. Soods good. [...] > +(define (elogind-etc-directory config) > + "Return the /etc/elogind directory for CONFIG." > + (with-imported-modules (source-module-closure '((guix build utils))) > + (computed-file > + "etc-elogind" > + > + #~(begin > + (use-modules (guix build utils)) > + > + (define sleep-directory (string-append #$output "/system-sleep/")) > + (define shutdown-directory (string-append #$output "/system-shutdown/")) > + > + (define (copy-script file directory) > + "Copy FILE into DIRECTORY, giving rx (500) permissions." > + (let ((dest (string-append directory "/" (basename file)))) > + (mkdir-p directory) > + (copy-file file dest) > + (chmod dest #o500))) > + > + (mkdir-p #$output) ; in case neither directory gets created Unimportant nitpick: please keep more than 2 spaces between the code and a comment (I use M-; in Emacs to do so); also prefer to avoid the space between ';' and the comment for in-line comment only (that's a 'may', not a 'must' according to our referenced style guide [0] though). [0] https://mumble.net/~campbell/scheme/style.txt > + (for-each > + (lambda (f) (copy-script f sleep-directory)) I've move the copy-script on its own line under the lambda, which is more conventional. > + '#$(elogind-system-sleep-hook-files config))j > + (for-each > + (lambda (f) (copy-script f shutdown-directory)) Likewise. Other than these tiny cosmetic things, it LGTM: Reviewed-by: Maxim Cournoyer <maxim.cournoyer <at> gmail> -- Thanks, Maxim
Ludovic Courtès <ludo <at> gnu.org>
:45mg <45mg.writes <at> gmail.com>
:Message #31 received at 74819-done <at> debbugs.gnu.org (full text, mbox):
From: Ludovic Courtès <ludo <at> gnu.org> To: 45mg <45mg.writes <at> gmail.com> Cc: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, 74819-done <at> debbugs.gnu.org Subject: Re: [bug#74819] [PATCH v4] services: elogind: Support Hook Directories Date: Mon, 30 Dec 2024 12:26:43 +0100
Hello, 45mg <45mg.writes <at> gmail.com> skribis: > 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 I integrated the cosmetic changes Maxim proposed, tweaked the commit log to better match our conventions, and applied it. Thanks! Ludo’.
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Mon, 27 Jan 2025 12:24:07 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.