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 GJWOLcW+YmdCaQAA62LTzQ:P1 (envelope-from ) for ; Wed, 18 Dec 2024 12:23: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 GJWOLcW+YmdCaQAA62LTzQ (envelope-from ) for ; Wed, 18 Dec 2024 13:23: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=ociedJ44; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=hHCE08lB; 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=1734524613; 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=hZ/3vG7WPxZlQYGPpC+RomcB13tO0ZbaW4EPShYqmIg=; b=DmxLfYyMX1M9/AfDUfA+8w4H3ilNZRqgpw9AK//EcBWTY+kFrs/7YMJm3o07XuXBxkwZCb ZwZ4F6X4TGFZD5ZQ8vPbicCyhInpTU0rOD5k6E8BmM9e/eQFOJxVeyM3MYoFeFnCd4ztc2 x6XKoRmf2GXX2nvlKoi78Xni3xQ9cFRAknF1blumTIeWoQ10GslLR3GZJDKWduf06yDGoX mi8qF+q9T8X7uurksxauLPjnadhK7bsObW++fCS1i1KsNWVUEXt79k+NA7HuP//00hd/YE KTwl4eTtZ5m3LAUa3AVzRs9I1O8G+2Gd3RqUl1g0qBEtbQw7nZzWe7QW2OwLbw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=ociedJ44; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=hHCE08lB; 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=1734524613; a=rsa-sha256; cv=none; b=B8pSMaTmKTjspB4zgcApv/yjU92J/J8Jny7XPDnO1oDTHF55tPkahVdV6OHDrhF49GfZTl KpA9liwtdEgtwWdqaY8AvdtSVYxzNv6ldRJgHAF0f4DXv4mPp0WbD9BishBKlqYBtoCxsC z8LumfVwT/b3zCkGD0wUJ8Qsswg5EBTuT0hBNmCL0E57jLhwHrMG5RKVVJe/XtFs06FmZ+ 6aisVzmRGDEIlJTLSAfuHyQ3ctkMsgm9Di1PYfrBi+fAi888SJ6LzyOG0Fbxfkz6rfVf6C uH5FJsnxsE/5Hh/rJHSNHfC7zARCVidx84/owFTOTZbbPwb7VCTo1J8V6SS7Og== 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 DF1227F6CF for ; Wed, 18 Dec 2024 13:23:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNt4x-0001uY-Ul; Wed, 18 Dec 2024 07:23:04 -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 1tNt4w-0001uK-S8 for guix-patches@gnu.org; Wed, 18 Dec 2024 07:23:02 -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 1tNt4w-0005J6-IG for guix-patches@gnu.org; Wed, 18 Dec 2024 07:23: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=hZ/3vG7WPxZlQYGPpC+RomcB13tO0ZbaW4EPShYqmIg=; b=ociedJ44OPdJ0+PiWW8fMnzNw27Uv/XdLt6C5yA0VlbaAMLB+ugN53eXAysyAunbNfHLSkleDz3Da9VJCRTEHy96qOtNO9H2gmKGWXLsuJ0XcwGJlWpS8jym0LerBXn0M7YO1UaW4Jh/sFhHls2ogHDt7DYCNJOiPJ2vBo/b5LppoehMiC4VgU2xD+wUEPtTvpThkrURk8MILYXn2yKnyRYapPSB2e/u1CgoFZMH8N0TGI1p/ZDXgPX5sPFmMPtjSqHsOboC08FdGHlRuYUIWRc4Lh0GeUn0lOVM5wDd28slrdWir0R/aqTvU7SYjy/sH6C0FtHPakaOQJY3uRWMfA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tNt4w-0000BG-9V for guix-patches@gnu.org; Wed, 18 Dec 2024 07:23:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74819] [PATCH v3] 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: , guix-patches@gnu.org Resent-Date: Wed, 18 Dec 2024 12:23:02 +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>, ( , Christopher Baines , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice , jgart X-Debbugs-Original-Xcc: ( , Christopher Baines , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice , jgart Received: via spool by 74819-submit@debbugs.gnu.org id=B74819.1734524558646 (code B ref 74819); Wed, 18 Dec 2024 12:23:02 +0000 Received: (at 74819) by debbugs.gnu.org; 18 Dec 2024 12:22:38 +0000 Received: from localhost ([127.0.0.1]:33810 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tNt4U-0000AI-00 for submit@debbugs.gnu.org; Wed, 18 Dec 2024 07:22:38 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:52350) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tNt4R-0000A8-J2 for 74819@debbugs.gnu.org; Wed, 18 Dec 2024 07:22:32 -0500 Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-2165cb60719so51509865ad.0 for <74819@debbugs.gnu.org>; Wed, 18 Dec 2024 04:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734524490; x=1735129290; 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=hZ/3vG7WPxZlQYGPpC+RomcB13tO0ZbaW4EPShYqmIg=; b=hHCE08lBh6gfir3yqwoIBzo4XuWfh5+KKGwqYVVdsOGp//GxLad0RD4mOEwfOJraqc j67JYJtBRwF7jyvM0nkCQJNKili87/3DSOEV3wBv19EqiYYdijECbS0w32zt0K6wNioo SHW203loThDj9/TRP349mlLyc3ZS/ix8VdU5QoEVY7rO89l/h+mooE65SLMh203whig8 njag5K3KJOItrFFDhA7uWAVJ6rhMBw1qsPcT7nAMxLDnO3j2U6cbXHlwT3RYKbhDC5uh 1GYbt0vJmyDMGpzCzK/i+C/oBp6ga8JRdyZ0yWpr2CB7QYtxrfcih0GfzXVNtq5cPMC0 nTVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734524490; x=1735129290; 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=hZ/3vG7WPxZlQYGPpC+RomcB13tO0ZbaW4EPShYqmIg=; b=EDG8JcV+KYcsxzhCCbJzfTn581gjjBPLFAHQnQXlWWf5mj/f+8ANnZ8vz9r0m+OlRC mTpK501EgX5uXNtELEhIt+oXboWLFUG1QsnWTs9m5aXcxiYDDfNhykophb02F5GUFRve qjFCrtMq+B3jqaF2cTHCfnpketbSrQUhfFg5WSHtSV9YDmkQu7QWg+jRMvy70qIVqvw5 D5x6zIU5t2yYtga6T0zXJxiA9gj4QdhjwkS58olDUqnwqBwpD+4fHNknV8SO+D11a4M8 aM7T8xc//w/xfSVACuv91SCNhAe/HUJ1pVJUvxh7b90aY+FqbAhZdaYAWYOqDrrXrPrI hVjw== X-Gm-Message-State: AOJu0YxZrTveycVUdPByrOleyLTYwTrhqcwLNtjDWbQng4eSjFWk94VX lfbTSCQCsRuuBbzTGOeddwkgmSdPwkgwWrwyFHls1OXZ3xX+ib1l62YU+d6+ X-Gm-Gg: ASbGncu7hsYxBlDp7GHcqpw6gcr8cIxbHpOQ4g0LSDibdy04gMrIxxbgwFCz0UWRoJD 0jmKx+ZdJ676SqLlcCN6x41dtYuOW9/5n8Fz5Q4q7mDAWJHUaextGYtJXgo9R2LEb1aU1gC7KtV 4bha5/48gRPHeInw1+x4ryR6UeGKsk1inxxSn6b9NvUmL8J7102LCEo6A2Lo4iX/yZbbstPL7fj fIbHc2dTPBhjA1EEXy25auDwXBZnfRblcvx3WpP5wx9GMJRvbJLckK8EslOw5q7zPsv2Q== X-Google-Smtp-Source: AGHT+IHXz6rxqT3Xv7pnie+sTVHykW/YxU+bPTVqbuaR57lzG2idT6wowWXS3zVbrQG28HHd+dePTw== X-Received: by 2002:a17:903:2346:b0:212:6187:6a76 with SMTP id d9443c01a7336-218d6fdfd81mr37240505ad.14.1734524490530; Wed, 18 Dec 2024 04:21:30 -0800 (PST) Received: from localhost.localdomain ([49.37.225.73]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218cb0bd0e2sm27965775ad.240.2024.12.18.04.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 04:21:30 -0800 (PST) From: 45mg <45mg.writes@gmail.com> Date: Wed, 18 Dec 2024 07:18:49 -0500 Message-ID: <1688c8ebd2c7d074edce3b27c0e439c5897ee251.1734524329.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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -0.83 X-Spam-Score: -0.83 X-Migadu-Queue-Id: DF1227F6CF X-TUID: QpR48GNwoaiX 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 ;;; 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