From patchwork Fri Dec 27 12:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: 45mg <45mg.writes@gmail.com> X-Patchwork-Id: 35859 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6E2BE27BBEB; Fri, 27 Dec 2024 12:18:13 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B83EE27BBE2 for ; Fri, 27 Dec 2024 12:18:12 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR9I6-0007Lt-V2; Fri, 27 Dec 2024 07:18:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR9I3-0007LS-Pv for guix-patches@gnu.org; Fri, 27 Dec 2024 07:18:03 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR9I2-0005lV-OB; Fri, 27 Dec 2024 07:18:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=H1dCMsSIBLZX5RysQRf6TeDbLGJSngNL1pcuvJQMGMw=; b=hpgIZBT9CDeg6VJY2j1DYfpAHCwd+Eu/rF5x7wT+/7yTyJ1QBGAbxxe70+lIu4iMShuk9b91PWydz+hhKSRsDr1zlc38aoQlxL3bMpffpqMeaxQ5JNK5BfYkQYbBH1XBBDwsr3Yj3SASLs6WkcmKv+1/I+VjOz6dwdSZb9lsgT3nRL+DLNsThsLDJl80zRz+j+Qxj6PWBWYCMbbiNYJ0tKETl1QH+PJ41lNNnK+cFkPOeiI7b+Yj4qcRp2pdlnGkLdStfTLf/1X3RyPD0G8DZqmtyNUZe3yMeGIkHb2xY2Xi6Ob5zxY2scz3zAs1Y+BwNpLLFB9M09jsjZl+75H0+g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tR9I1-0005an-WB; Fri, 27 Dec 2024 07:18:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74819] [PATCH v4] services: elogind: Support Hook Directories References: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> In-Reply-To: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> Resent-From: 45mg <45mg.writes@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Fri, 27 Dec 2024 12:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74819 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74819@debbugs.gnu.org Cc: 45mg <45mg.writes@gmail.com>, Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 74819-submit@debbugs.gnu.org id=B74819.173530184821432 (code B ref 74819); Fri, 27 Dec 2024 12:18:01 +0000 Received: (at 74819) by debbugs.gnu.org; 27 Dec 2024 12:17:28 +0000 Received: from localhost ([127.0.0.1]:44955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tR9HU-0005Zb-2f for submit@debbugs.gnu.org; Fri, 27 Dec 2024 07:17:28 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:50419) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tR9HS-0005ZT-2j for 74819@debbugs.gnu.org; Fri, 27 Dec 2024 07:17:27 -0500 Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-216426b0865so85189925ad.0 for <74819@debbugs.gnu.org>; Fri, 27 Dec 2024 04:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735301785; x=1735906585; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=H1dCMsSIBLZX5RysQRf6TeDbLGJSngNL1pcuvJQMGMw=; b=eoGaM6YCkQdz+KffFMHo2AurPlTn2Q8/HS/IIi1yI84Cdw08YNlh1czkB4JpMGOqMs GHPUMG3KT1ogRee4HW4XPuL5S33Fx0yuHE5MbADX15KVDTSj5CV9z3zF2SPfXrCs0c++ WONBt1wExyXAYRdy6jPVVFkmMrIf8dB7cTe5aSTu+xDp5mT79NmU51V3vGu5C/jHELro xWJMIZ0ClPUm3wmVIXlxras3DBGAd52yISrBfllYNMqBqhS/OOy8fOB+9Mwr1iwTUSM7 DgfDNFAruk0w7WpPiHADZ7zIXOKCpAbBIMzSZw35rIhV/IhEo0HdLswvF5LBTrz2AvZH yFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735301785; x=1735906585; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H1dCMsSIBLZX5RysQRf6TeDbLGJSngNL1pcuvJQMGMw=; b=VelcRyqbCAp3osSW7kyPKWbpz80SXxGpnm08AZfbU2o/gxixDb0SNlyojY2EpSbGhg isFT2uZ+1/+BXddRiOrrJPE5PMiBhwEDR9TKQICf/GG7hAzQqG/ffZwGfYenWrwhunX7 J2+kWwpStyK0x9i0Esc5WKg4oOHjC/J03mgszg+Wt6Zvc78eqT8tyiAYtTu/HT37s5Fx x2HJSJEkLiqoiEXnxZTu+K91E51MVtmHdWCqe4CoGuFHZwYhTib+kxsjsscQyyrG52hp UtusncMhcCvxJj5ZE1Y5PGsLoDzSZtXvMvVnsJVLB0okd2RnVm+0Z3JqWdCrUASqIKSF ANcw== X-Gm-Message-State: AOJu0YwesFQqwHc5zHwSM5CF7CoBLcb9hQRN0CQqXedbHmUbhSuJrAIb c3TKOrX9xDE6sS0D6i/GE6cMZ95BUPAgvS0i1AbGNbQP6hgP95Mw04NyjsFY X-Gm-Gg: ASbGncsRRxtQuULmSZK05Ti5MEl288ummLlIe8CiIvAKLoXSEPpNIExmkgBeQTdwjv1 JYGHcQmYpLU9S9hEpwq9rZl9cUH7OcY35pqnNflHyx0q5rcb11JGGOY6LLzpTMLChcsglQTs2NO yJ+XcyhKtFs007Fw31aknsJqwevj8+o++6VsR92v303Du7q5cGV88fPgTBZxLg+1WJ7OZsBBA4N gpOOJwvsyH+Ixw8awrOI7k+R0UWipTuFHoIFu4H/tX7KtCqlG5agnt18Tuobn/LY5u64mE6vz02 X-Google-Smtp-Source: AGHT+IGfoGTujcBI4R5uwAjk0YIVNVjt2h29Eq0qXf1D1+8hBJaxPi85CQVqMpt6kcH5tX8vaX+2/w== X-Received: by 2002:a17:90b:2dc8:b0:2ee:c797:e276 with SMTP id 98e67ed59e1d1-2f452d3000cmr46799806a91.0.1735301784700; Fri, 27 Dec 2024 04:16:24 -0800 (PST) Received: from localhost.localdomain ([2401:4900:1cb8:a2d3:f4aa:1246:d469:678a]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f2db9a661esm11721793a91.2.2024.12.27.04.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 04:16:24 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Fri, 27 Dec 2024 07:15:02 -0500 Message-ID: <276103d4ae303592ff8ce4e83438e8c3d1c020bf.1735301702.git.45mg.writes@gmail.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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 Reviewed-by: Maxim Cournoyer --- doc/guix.texi | 27 ++++++++++++++++++++ gnu/services/desktop.scm | 54 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 2 deletions(-) base-commit: 3ada4796e9adcea6fce621e639ddbfb181ab6689 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 ;;; Copyright © 2023 Bruno Victal ;;; 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 (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))))