From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id eLa0DWDhWmevaAAAe85BDQ:P1 (envelope-from ) for ; Thu, 12 Dec 2024 13:13:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id eLa0DWDhWmevaAAAe85BDQ (envelope-from ) for ; Thu, 12 Dec 2024 14:13:04 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=ugOX+a8h; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b="dP/GzILw"; 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"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734009184; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=+FSJuSFBPJ4FwTxS1K8zaryH8mlqSw6QoR4tVAv4XkY=; b=Qp+GnHjhOih5aujcY8/6ZyIFh1UioTjUbIvJru+40fax6GhDYALABgjkLKx/2ImC8w/vZT diXDn8LZ+Dv1/v9BTuBz3JHyREcVPVw71wOxzQAUyVexFeFkAH0lJ4BswpeKVB6Q7EeCb8 sPXN9V3L2oTpyu7vHoiq58QTUQ9AqogitTufyM1XivV7JsYoHLKDVQ5NX0IgAmj/cAh8tO ZiyItBVNnDndwdFGPSD3sZqzpOpO924wIW1V6gcu6IG3aY9uTzqGxT/Ua+Q6E9QYwIEzZN cO+K3CSvRob5W5easJastktPxCxDYD8/8iYM3M9A6QlxoWy3BXj9pV/CFgZyZA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=ugOX+a8h; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b="dP/GzILw"; 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"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734009184; a=rsa-sha256; cv=none; b=aXITlUJiDSXc7jLOmD0/gqkqMPupYQtexojoJrrvwUr/1aUwfeHPJGtD91HdRm0Lfn1nKW cvgzHU+4zssPWG3D3znecjKd1FtxFmBIC3pRVDD/1RBkzIXNdtTM+ZWeHjZxoJXIHybfcF ZtYieueLAtniVmXGSiqHweKvGDVDIXFCdUkHZryGqGQhdB4V/nXjeDfct0UOzWhO9mRLib vwVVBp4fqtO6gaFbMHKa5JiFo8c0z9RmlgpLYROOwxYveV33nplTKoGpugdLWninIndNFZ A21QbZ3nqD4aI+vxRitZ5OUzjYrtzAqMGr7YTUDh7CPMB4eu48qJeFV/0wMK/Q== 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 08A9482850 for ; Thu, 12 Dec 2024 14:13:04 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLizi-00021e-5Y; Thu, 12 Dec 2024 08:12:42 -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 1tLhTE-000580-9i for guix-patches@gnu.org; Thu, 12 Dec 2024 06:35:04 -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 1tLhTC-0003Wv-NS; Thu, 12 Dec 2024 06:35: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:Subject; bh=+FSJuSFBPJ4FwTxS1K8zaryH8mlqSw6QoR4tVAv4XkY=; b=ugOX+a8hVtB0k6vcVLZiE1zfIJfFnulAebYecJc2wLvv+UqEzvXpXlYIZ0NEE6tXdOMkilqD8w5/eYBNPXRadGENUb3jIaYiiZ6sGvq+kVPte2ok4uYvnVK1mxqDMDYX3Kd1Zpp29HGnUtyDzp/OcD5GDSNSjnQxIA19irxMlFBGx5Gl9kxbWsbqx/yeQQ4eXtjmI4IrF/PPkGsOl+1qCE9ynwAS+PB2JcI8gwkqeoPOGRXiabsnPR/KlTeowxk5NYjuTH5OICHnpWZqs9g/bF5VQaetbPMwxIPX26Z/5OnjT32iblwSKc2Y+5YWpj6lNS5/0LiRaYyl/BygiHQ3Xg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLhTC-0002QM-6c; Thu, 12 Dec 2024 06:35:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74819] [PATCH] services: elogind: Support Hook Directories 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: Thu, 12 Dec 2024 11:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 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-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by submit@debbugs.gnu.org id=B.17340032719260 (code B ref -1); Thu, 12 Dec 2024 11:35:01 +0000 Received: (at submit) by debbugs.gnu.org; 12 Dec 2024 11:34:31 +0000 Received: from localhost ([127.0.0.1]:37941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLhSg-0002PG-No for submit@debbugs.gnu.org; Thu, 12 Dec 2024 06:34:31 -0500 Received: from lists.gnu.org ([209.51.188.17]:45982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tLhSd-0002P1-9X for submit@debbugs.gnu.org; Thu, 12 Dec 2024 06:34:29 -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 <45mg.writes@gmail.com>) id 1tLhSd-0004wW-3f for guix-patches@gnu.org; Thu, 12 Dec 2024 06:34:27 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <45mg.writes@gmail.com>) id 1tLhSb-0003Tu-74 for guix-patches@gnu.org; Thu, 12 Dec 2024 06:34:26 -0500 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-725f4623df7so387938b3a.2 for ; Thu, 12 Dec 2024 03:34:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734003263; x=1734608063; darn=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=+FSJuSFBPJ4FwTxS1K8zaryH8mlqSw6QoR4tVAv4XkY=; b=dP/GzILwND+d3trXogdqPJdi04XulzR5+uUW2v/920gin3PeNbmxRF6Djz3HU6UCfw BbjugEzpmBe2ByKMNt/SgKDz1H23mQsSEzNMtOt41RfbnZwlwqDVcmuHMjnwVHcez7GB fqPIU6DrTCpNLDZIIG2aEmrcbuZdmxcWJ8XPXC873JWIZLL6hjXoYAhrylDwBMObztqy Wc40NFBmozup6Lri+2SQPpPK8nYjghY8YlaG3KCEBIHZj+nncxnqUs7ll6j9CIiSbUj+ hhZI+4bsUz4uSwhpMfUaVo5IlAYV0WhrPRWpEkvU9jpn84mSTNNZ8CLzvPM554iMj7UV aNHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734003263; x=1734608063; 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=+FSJuSFBPJ4FwTxS1K8zaryH8mlqSw6QoR4tVAv4XkY=; b=CuzCI94oUi04pbUBTzBv//A2EPW7rOwgTgl6gq1vffXDhzXdDyvT/h8UDr0gjTZPCe mE1HUlJ+X+1u4+iNL1uwNFHU1EnKKKwz3ZG/QypuSol0gkllfJYhZX8XIgZ0SOsgI0dv bbpiTHPKBf3qZcDygsehQjqykEskGPd85cRFwWE2zloHDR+qxK0mB00prXrkvAWefZBj bQj+1D93NiHVjNz+AxCSZIBHreelPsfcVMc0pXoxzkwyDfhRduAHF+zugobI+mT9XaXQ ershegB6sg1GHS575mXOy7frMMzgqcrmYvggmB1+vB5NxfLywqDvnkVqngdFuGqoPHe5 DNUg== X-Gm-Message-State: AOJu0Yxy75JA6CHbrkEBtSOgA2onPP4epJc3M11wB/rQXXE2FptADhQ6 G3g0+SOyFfxJFxxTDB9XzXOOxOtObJaKYlYah+I12D2pkwAuyAumXSmMkhDj X-Gm-Gg: ASbGncvYNdSyI9g3bnb8gOhLeIBaVxRYlLM8PL2rfAoNKmU//1iWJKJ3zKgPTe0cMZx aP7Hk4W+icMGbMr7sZJJuiyVsbXdvtG9412UhTZmwWg1qCCzP5YkELge9n3c5Qoa3287alpsM5W 53tE+eVTgyp0fOneqGHyKQ2bqaQ8qaZtECVC7LeHWvq2aMyg8F4C7ailLMbMSdSBMwLlN/GLNkj MbK5tNIvSZLstJCPRrnnbQjiSMawh+6Ih0DVwqhZF3y+tFzPutFZlqAhhwrLpNd7FfWM3w= X-Google-Smtp-Source: AGHT+IHwdYdyzsuLSwahX1V/IKOEyXkJ/WFfpxAt+t1c6V8/spYwDLQ8CbFtYPNgM269FfS0cPN8cQ== X-Received: by 2002:a17:90b:33c2:b0:2ee:ba0c:1726 with SMTP id 98e67ed59e1d1-2f128044bdfmr9049796a91.34.1734003263101; Thu, 12 Dec 2024 03:34:23 -0800 (PST) Received: from localhost.localdomain ([122.171.19.44]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142db1a16sm1036469a91.15.2024.12.12.03.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 03:34:22 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Thu, 12 Dec 2024 11:33:46 +0000 Message-ID: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=45mg.writes@gmail.com; helo=mail-pf1-x441.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Thu, 12 Dec 2024 08:12:39 -0500 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 0.71 X-Spam-Score: 0.71 X-Migadu-Queue-Id: 08A9482850 X-TUID: z7PNiMnT7OfV 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 ;;; 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,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