From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id UB+RHQnJX2cZrQAA62LTzQ:P1 (envelope-from ) for ; Mon, 16 Dec 2024 06:30:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id UB+RHQnJX2cZrQAA62LTzQ (envelope-from ) for ; Mon, 16 Dec 2024 07:30:33 +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=PYJX3jGZ; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=k2Md+rU1; 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=1734330632; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=u08o21WyOY9e+hH8Nay/edDqoI4rHOn0j05FMblAa5c=; b=s9uNc/mR7XLrdto2lZjnn15tP68G+dI48kCxQ6rpQrWDDrd0FH+eK+lbzr2sMEsR+yagLT rV4sLGtmiNztxc12ycziPKRiTvwyCblJ0P92qO5SLPI1aM7E1dVzqA09gXBNQ8HE9GWi5T XcwzW6tYgLF6OYJyurVhChLu9vHxUkbi7plrumVc7mVr8VbZR9Kj1QwbtXuQS6O+Frz/cK /EnHPkE58GIu+59RU3WpeDcG2mzl6gBt0vbvQpW/7fSYNI26YunTdh2nOLPB2tJiB0TSqe WNHJsyhj20xEOw6egi++rfKsfxSo8D3m5deRvN/IZUiZovjDdWWXh7qEPdV5aA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=PYJX3jGZ; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=k2Md+rU1; 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=1734330632; a=rsa-sha256; cv=none; b=JAQK5qFGkpQbfty3Y/kQfcUthhfQmc1rJMKMs4WIGAuDt6pi91BV3huP9blRC09oAR0BPL +6mPJXYRoqNMPH6sdav0wZszTKBIygUKwRLWgkFZCJMvXzvLmIWU00NNDwK/BaIH9R3WdU fztnjFKLKNVeur5d9+Kn2RgHqlHlGsbQOAYbgcfT7/Cx3Ob9EtQNzQdNrl9qlrnh3baDdj 0ZXp7jeOZexCfvK6YK82OsaTt+ycsA37YmaxvNX9e8gZZiJXWHl4EHMppyMZqWOb4g6Vzn aGAtia905JeXkWPkKVeutwbAHnbf/DgKd7xw1MZaONCcceSMhrfKDPp3q1sgFA== 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 7A52C7FC7B for ; Mon, 16 Dec 2024 07:30:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tN4cQ-0007pm-OV; Mon, 16 Dec 2024 01:30:14 -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 1tN4cL-0007mO-VP for guix-patches@gnu.org; Mon, 16 Dec 2024 01:30:10 -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 1tN4cH-0006TN-Sb; Mon, 16 Dec 2024 01:30:06 -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=u08o21WyOY9e+hH8Nay/edDqoI4rHOn0j05FMblAa5c=; b=PYJX3jGZjAa++fNymUV/LPixqBMIwphX8nmKEyQS++UfioOw34XCzasORVRSJkZXFJAwRXZ+cFwSBw2pXcVSaYZsV5femhZ1xDtDZNYVQcl2vl6Mx5EZEFhvOapQ6h45zHP+RgQ46AB39Uw+vHY+9PL+j8rnFpwOUvyHCZb9Sup6RACndiaQX4DlOA5sRfCKLnjieO+qC938iWCWBjCzu6RXEEZQ6F7idZA5p+57XmRTBB8SpEwE+PVqX/qn1bi9Z/plyzUR78NJlHjkMM9R4lH0edkthsS42nbpk8K30Ktt1I4QF3bb21xGqelT2oMk9xajLtklv78DZTvYR4myMg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tN4cF-00053r-8M; Mon, 16 Dec 2024 01:30:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74819] [PATCH v2] 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: Mon, 16 Dec 2024 06:30:03 +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.173433058219366 (code B ref 74819); Mon, 16 Dec 2024 06:30:03 +0000 Received: (at 74819) by debbugs.gnu.org; 16 Dec 2024 06:29:42 +0000 Received: from localhost ([127.0.0.1]:53213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tN4bt-00052H-Tn for submit@debbugs.gnu.org; Mon, 16 Dec 2024 01:29:42 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:55465) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tN4br-000522-EK for 74819@debbugs.gnu.org; Mon, 16 Dec 2024 01:29:40 -0500 Received: by mail-pl1-f193.google.com with SMTP id d9443c01a7336-21636268e43so45593285ad.2 for <74819@debbugs.gnu.org>; Sun, 15 Dec 2024 22:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734330518; x=1734935318; 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=u08o21WyOY9e+hH8Nay/edDqoI4rHOn0j05FMblAa5c=; b=k2Md+rU19n+goaEEXd93vtMl5kO+o+KQ56YNUFh+UVV7gONpnNWTWHgieRzybe9SWY i1t6RKr8077PtC6P8uCKPIR2dO40HjTVB80SyYcM55Jo8k3nYmlEQPxM9gNUrM9+AESx GFu8AIIC9Y3GveLOyZrHSNZJ5k1mARlYMzJ21ABT93a527+22CPUAFK+iX/3/7LhpKvz QJKqtONvccpCGLPgGo97jJnfpf+tz4QoCe9WjNHp1yuWsqD+FOFCoQ8QQU6GsRVM3ikc hItMzqn74E1Mcn+maDmRflRrv+01WAvuwhHNeDadEiAtq+2w/asXKFoJ/SUgesWTaxJi gkyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734330518; x=1734935318; 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=u08o21WyOY9e+hH8Nay/edDqoI4rHOn0j05FMblAa5c=; b=wBEPMuKVl9Ali7KFyRC8oFylzfYueeUrKopeme+VeuPD7Wfw+/HpiGeGqmIgld2sd5 /yEEsEIfSGuZclzwFxWJ227aEbo51aUqAEkUYwMrQokw5JRmD8ikMBUy44SLsnrU20vM EgNIKEWMbFM+nsL/wgUZwY6+7xzFpDvXqyD6GvGUULrjUFACE72PADTFJGrMdJKaq/sX pgr5ZDZaMNDaWiZndptbTys6058RFI8tC6alJg/x5qS2vamyjBlYhQkc/en7hLInMgEE DuqbnBt/4WrIpGqNRlj3gbd/xKd9hu0tM4KVYe1H4SdDlg0pDrP1adfjSkSzjrLFytkZ 2wmw== X-Gm-Message-State: AOJu0YwntyuQ7ERfuzfVolVaaQfbTIMfPlCt2E0IYtZ6WHwf2Ub0i5XO 8oT96Razs76RzmmwNQ/h5QbckzXfYSAkcwk0SpKN8sDrAYujv4gBcOaJWBgPlKY= X-Gm-Gg: ASbGncv3qwaQ2bkPLyD414eDqNhL/NWlM9VrQ6cMQyXok0P55G00AIPBqPOPSjFnl+L 2A03KCNcw1d4MMUzl29AJjvrvNBHQ5fBAuOmAXlhrEZDXB0MGYKCOh8DmuOF+cIBbPWAMrQka/u UZRiU7YHcN6aFX61CpTgugtPWwb+9QOzVXTFIFzzm7XODho1TyfMvTxqwcAkgUWf/9Z7MM0uq5O 5Inuc5W9Hpl7opTKrl24N30BXd9/Cs/zdjvMwDE5g02oKdtSa+XNR+HO3Ouv2cRna7tVJua X-Google-Smtp-Source: AGHT+IGnfnqYSrpEAcjEmLOBC5OiJxt3bTngi+ZnYQPQCoFD/KlLnChf1J/x7GsIOHfQzcn9mQHsIQ== X-Received: by 2002:a17:902:cec5:b0:216:3083:d03d with SMTP id d9443c01a7336-21892a337f3mr166534635ad.44.1734330516906; Sun, 15 Dec 2024 22:28:36 -0800 (PST) Received: from localhost.localdomain ([49.207.229.110]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5a90ba0sm3443956a12.16.2024.12.15.22.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 22:28:36 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Mon, 16 Dec 2024 01:26:50 -0500 Message-ID: <5cda8ffd81510c445eb900de584305a8f26d3b3b.1734330410.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 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 7A52C7FC7B X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -6.27 X-Spam-Score: -6.27 X-TUID: IDAUCkSaL5XC 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 ;;; 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,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