From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 12 06:34:31 2024 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> To: guix-patches@gnu.org Subject: [PATCH] services: elogind: Support Hook Directories 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 X-Debbugs-Cc: Ludovic Courtès , Maxim Cournoyer 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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: 45mg <45mg.writes@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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 From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 12 08:02:08 2024 Received: (at 74819) by debbugs.gnu.org; 12 Dec 2024 13:02:09 +0000 Received: from localhost ([127.0.0.1]:38150 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLipT-0007ab-Kp for submit@debbugs.gnu.org; Thu, 12 Dec 2024 08:02:08 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:60770) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tLipQ-0007aM-3u for 74819@debbugs.gnu.org; Thu, 12 Dec 2024 08:02:05 -0500 Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-21654fdd5daso4697805ad.1 for <74819@debbugs.gnu.org>; Thu, 12 Dec 2024 05:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734008463; x=1734613263; darn=debbugs.gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :from:to:cc:subject:date:message-id:reply-to; bh=krsKJ/QsZs8ApbF6wQLCvrjwqzMQVIw28RbAOO4WAXQ=; b=KbP60UBbzf9xcsgWPTc6H9Xi4ayQWMaTCh1ifl+WXzgaLeyxubWHZkAJuckKXLT90J LhM36QtcGdgbdkhaboZM2Jgnyum1PfkFEiQBYobhDZXRJIQw2serQ9+emvkvDvedxDcV jSMez+Jm4sfM2IBux+A43UfoTou8peg5S3s8uQqNl2vcMS0AJfgVdlINfx4cNabtPaiT fuCC3+8ETzutxmKg5p8pM7t3zFerFgU1puB1E6DfjEP+iG0/C9Epg7TEJnoAkrauh9U4 6Z9I6KnKhtW0U3T+a0DDoThZogG/H/ItOzoriP/bBqT3fUWlzekXMEQOV5I2kxm4S6Do oIAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734008463; x=1734613263; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=krsKJ/QsZs8ApbF6wQLCvrjwqzMQVIw28RbAOO4WAXQ=; b=Tfa/wIko+AWrNeHlK7v01vGrFejHJbGSqoZKML1DtS/BDdoovsiwvV3Do+SK85fidC 1WFzIQXUmxgYcGGg2tR37ggGYC1N1gRuPc8CJl3Sih9nxQ2P2JbaGHA9I+E9jLG7apXc bz9L1c759C2zhjDCGTwd5eD6OoEU9VRtxVePKyg1jV8LPoPCvce45yL514p5qY2OiVsD xhQ1Dr/MKsur8CWVGy0pwOwekxNSDpTeCbdwIRnPc/f7XdGh2EvySyVDPK4Gdcgj8W4Q n5HhetPhp9YnMyWi6KThb6slH7bNTY37CfzLzV/zWkWIPLTjO2g67McUBB7wq0WqeUIs rE6A== X-Gm-Message-State: AOJu0YwiSZ8ILo7deWA5x8+sGDhcfWJ3ayz1CmFdZCSZNird8rMvLYyG AEVc6+HtUbtkqpx+fQ764RUKLKSYQA0UemWUugnkRIrFpI0OrKETGVexr7RA X-Gm-Gg: ASbGncvUb4/0zSgrwCUrthzJgkowBYc39+Ohc2wIKWWqEJLBVG2ZxdPTZbSNaspqz4j WIM9xROpS0Ndu1rJIQpk4AboEnFUXyqENAnM+yZ96kQLUMJH6j7N5cliIFkyS4i1hy2MjMXofn0 ezu0VFRhQPtbNlVlRrBGBpwf/EI6D11PPv+srjcBpCLb5Vxcw2nBquuaKq8WpJKQWJTKy0m+zL2 KksVXfUA+WUzuzORwVKY01cpIDqIimRbco3mlZb9gSTj7Er0g== X-Google-Smtp-Source: AGHT+IEnu0BYrfF2Q7ZK4VQvtmsSfvDVAZndhz+GoqlUQWDnqsSXhQm+Fw3D3Z63VX62e76FOzh3eg== X-Received: by 2002:a17:903:1c7:b0:216:4c88:d93a with SMTP id d9443c01a7336-2178aee72c4mr48189765ad.48.1734008462853; Thu, 12 Dec 2024 05:01:02 -0800 (PST) Received: from guix0 ([122.171.19.44]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21675035c6dsm45460495ad.165.2024.12.12.05.01.01 for <74819@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 05:01:02 -0800 (PST) From: 45mg <45mg.writes@gmail.com> To: 74819@debbugs.gnu.org Subject: Re: [PATCH] services: elogind: Support Hook Directories In-Reply-To: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> References: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> Date: Thu, 12 Dec 2024 08:00:51 -0500 Message-ID: <87a5d1ys1o.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain 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) --=-=-= Content-Type: application/octet-stream Content-Disposition: inline; filename=test-config.scm Content-Transfer-Encoding: base64 KHVzZS1tb2R1bGVzIChnbnUpCiAgICAgICAgICAgICAoZ251IGhvbWUpCiAgICAgICAgICAgICAo Z251IGhvbWUgc2VydmljZXMgZG90ZmlsZXMpKQoodXNlLXNlcnZpY2UtbW9kdWxlcyBjdXBzIGRl c2t0b3AgbmV0d29ya2luZyBzc2ggeG9yZykKCihvcGVyYXRpbmctc3lzdGVtCiAgKGxvY2FsZSAi ZW5fVVMudXRmOCIpCiAgKHRpbWV6b25lICJBbWVyaWNhL05ld19Zb3JrIikKICAoa2V5Ym9hcmQt bGF5b3V0IChrZXlib2FyZC1sYXlvdXQgInVzIikpCiAgKGhvc3QtbmFtZSAiZ3VpeC10ZXN0IikK CiAgKHVzZXJzIChjb25zKiAodXNlci1hY2NvdW50CiAgICAgICAgICAgICAgICAgIChuYW1lICJ1 c2VyIikKICAgICAgICAgICAgICAgICAgKGNvbW1lbnQgIk5vbi1yb290IHVzZXIiKQogICAgICAg ICAgICAgICAgICAoZ3JvdXAgInVzZXJzIikKICAgICAgICAgICAgICAgICAgKGhvbWUtZGlyZWN0 b3J5ICIvaG9tZS91c2VyIikKICAgICAgICAgICAgICAgICAgKHN1cHBsZW1lbnRhcnktZ3JvdXBz ICcoIndoZWVsIiAibmV0ZGV2IiAiYXVkaW8iICJ2aWRlbyIpKSkKICAgICAgICAgICAgICAgICVi YXNlLXVzZXItYWNjb3VudHMpKQoKICAocGFja2FnZXMgJWJhc2UtcGFja2FnZXMpCgogIChzZXJ2 aWNlcwogICAoYXBwZW5kIChsaXN0IChzZXJ2aWNlIGVsb2dpbmQtc2VydmljZS10eXBlCiAgICAg ICAgICAgICAgICAgICAgICAgICAgKGVsb2dpbmQtY29uZmlndXJhdGlvbgogICAgICAgICAgICAg ICAgICAgICAgICAgICAoc3lzdGVtLXNsZWVwLWhvb2stZmlsZXMKICAgICAgICAgICAgICAgICAg ICAgICAgICAgIChsaXN0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGxvY2FsLWZpbGUK ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInRlc3Qtc2xlZXAtc2NyaXB0IikpKSkpKQog ICAgICAgICAgICViYXNlLXNlcnZpY2VzKSkKCiAgKGJvb3Rsb2FkZXIgKGJvb3Rsb2FkZXItY29u ZmlndXJhdGlvbgogICAgICAgICAgICAgICAgKGJvb3Rsb2FkZXIgZ3J1Yi1ib290bG9hZGVyKQog ICAgICAgICAgICAgICAgKHRhcmdldHMgKGxpc3QgIi9kZXYvc2RhIikpCiAgICAgICAgICAgICAg ICAoa2V5Ym9hcmQtbGF5b3V0IGtleWJvYXJkLWxheW91dCkpKQoKICAoZmlsZS1zeXN0ZW1zIChj b25zKiAoZmlsZS1zeXN0ZW0KICAgICAgICAgICAgICAgICAgICAgICAgIChtb3VudC1wb2ludCAi LyIpCiAgICAgICAgICAgICAgICAgICAgICAgICAoZGV2aWNlIChmaWxlLXN5c3RlbS1sYWJlbCAi ZHVtbXkiKSkKICAgICAgICAgICAgICAgICAgICAgICAgICh0eXBlICJleHQ0IikpCiAgICAgICAg ICAgICAgICAgICAgICAgJWJhc2UtZmlsZS1zeXN0ZW1zKSkpCg== --=-=-= Content-Type: application/octet-stream Content-Disposition: inline; filename=test-sleep-script Content-Transfer-Encoding: base64 IyEvYmluL3NoCmVjaG8gIiRAIiA+PiAvcm9vdC9lbG9naW5kLXRlc3Qtc2xlZXAtbG9nCg== --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 16 01:29:42 2024 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> To: 74819@debbugs.gnu.org Subject: [PATCH v2] services: elogind: Support Hook Directories 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 X-Debbugs-Cc: Ludovic Courtès , Maxim Cournoyer Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 Cc: 45mg <45mg.writes@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 16 01:38:24 2024 Received: (at 74819) by debbugs.gnu.org; 16 Dec 2024 06:38:25 +0000 Received: from localhost ([127.0.0.1]:53244 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tN4kK-0005aV-Lo for submit@debbugs.gnu.org; Mon, 16 Dec 2024 01:38:24 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:52493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1tN4kJ-0005aL-0q for 74819@debbugs.gnu.org; Mon, 16 Dec 2024 01:38:23 -0500 Received: by mail-pf1-f193.google.com with SMTP id d2e1a72fcca58-725ed193c9eso2944259b3a.1 for <74819@debbugs.gnu.org>; Sun, 15 Dec 2024 22:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734331042; x=1734935842; darn=debbugs.gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=O9wh0w4c6yu0cbsSHA43DghSNshJSGc6cJd5WkytCAk=; b=HtpJj2D1TPElV8HnnNoefytpdHgih+XIQg+cUcMUiIIt0AeUHO2GsB8QNH94YIBeVa wv/vWfJDPsuXzTvT11NLCIkR+iOAlgGDLOKaeGIuwAZcS7smOvmKPP02GDyk7F+YXSQe QBOMxsPygnGTr/uzyema3t7lG5cDzmTgYCJX1fPSxr9owpvCsX1fxlgWADDWDKdxKmXP 4sZb6v0vac63kJN35TNkDtxvvY/t5jBh4zvd0fwRj4sQO+TvHlXLPlS46pDUKPRLPS8X jbWcsfnZJ830PRDgSl/b/OJQhe/DInJZILhyTOMBN5dGwAtpmyQsfmIywUP4zS9t6jOw Rdew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734331042; x=1734935842; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O9wh0w4c6yu0cbsSHA43DghSNshJSGc6cJd5WkytCAk=; b=GodB5a1yoVFkDUalthAGCfx1hchKIcfny6zLNOwHDu6jHDExvpDd5nBHojGgFEFx3t Y4324c4/NYo/X2Y/WuW/KW3CVUA8hoKVdUJ9K2Oxp53C87uIGfuN8dXYl3QL4MmkrLa9 pT/C67GGDuGeTO/WhqU9RNHyeupCPl1VDizdmyriclCwsFEqRYlSUQPXiycK1NOIN1Wx N5t5CtpilazlisWIsrY+BioKCxKWOzBeXauCjaao95G28Gsea8UxsD15l7Op+1M8HBzq PpZzUIBk/UVgjwr5enbwyWScPQoH4xajGTU8G2aYd39GV828Z4zmkNfoPTWGwqxPi/pS EGzw== X-Forwarded-Encrypted: i=1; AJvYcCW6hllOYPAjxxiOYHX7JkB9IOhob6hqN1CZ0WcCYKEdD36QQCEyrfQTK20fz89eQXLSAVGCWg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzWNl4sE6tDyEqjG7kbFi9/TR2LGPbA8Ec6QcDjEazYl7bKBOBT eKM18wdyUMgXmDmuO+xEUCfxiU5KpFPe9aqajWH9wnQlnnm+YIU9cC0JlOByKr8= X-Gm-Gg: ASbGnctc38NQY0QSBa4heT2QnkGDtfsHTGWh/Dy4WZc2sQSEpAi7yjJFSLrWv13FYeb 0ztaRwZHMxuBnVNdJVk3+aqtiVyJsJijpLSeD2G3Kcy+Ep/xzPQRzR4j4nQxGGZaoYv4icF3viR nsUyLRh0nCxrroy9OMVq8JdeO4fZlZtEiF5eogaCKlG6EwH4ENPU1x/5ll5A0sYnSwmryxTUcBY sjpUFVJUzrPyO7z9iT4wIDYSuibFNsmS0gK+fjl+Ghi530UvY0= X-Google-Smtp-Source: AGHT+IHwrSxnpenq8uVupWXN+AZ7kzfBs7b40Xi/yYi+LOMmfy7q4/D5k2ry8emF4IELJtI9TyFFmA== X-Received: by 2002:a17:902:fc4c:b0:216:6855:15f with SMTP id d9443c01a7336-21892a41ef8mr156581415ad.51.1734331042415; Sun, 15 Dec 2024 22:37:22 -0800 (PST) Received: from guix0 ([49.207.229.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e5404csm35757895ad.150.2024.12.15.22.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 22:37:22 -0800 (PST) From: 45mg <45mg.writes@gmail.com> To: 45mg <45mg.writes@gmail.com>, 74819@debbugs.gnu.org Subject: Re: [PATCH v2] services: elogind: Support Hook Directories In-Reply-To: <5cda8ffd81510c445eb900de584305a8f26d3b3b.1734330410.git.45mg.writes@gmail.com> References: <5cda8ffd81510c445eb900de584305a8f26d3b3b.1734330410.git.45mg.writes@gmail.com> Date: Mon, 16 Dec 2024 01:37:19 -0500 Message-ID: <87ttb4m8v4.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 Cc: 45mg <45mg.writes@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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) From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 18 07:22:38 2024 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> To: 74819@debbugs.gnu.org Subject: [PATCH v3] services: elogind: Support Hook Directories 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 X-Debbugs-Cc: ( , Christopher Baines , Ludovic Courtès , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice , jgart Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 Cc: 45mg <45mg.writes@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 23 13:00:44 2024 Received: (at 74819) by debbugs.gnu.org; 23 Dec 2024 18:00:44 +0000 Received: from localhost ([127.0.0.1]:56070 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPmjT-0001yy-H2 for submit@debbugs.gnu.org; Mon, 23 Dec 2024 13:00:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPmjM-0001yU-Sz for 74819@debbugs.gnu.org; Mon, 23 Dec 2024 13:00:38 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPmjF-0006mK-Gl; Mon, 23 Dec 2024 13:00:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=WSK/zWp/nFTLuAEhsV3KVfEpIdzWBb+XlfTo6tnAe74=; b=Xzf0HYW8j4Y41T76pS2r KIvuk9EHCkI5MGO7H8WeAjH6lP2IfdKEDa4nroXy/epDW8UV/KUKkZ9ymVkHToyytn7Y9iG/qSaoR NNLCh6UWu2hyT4kriSABFtOJRpveNH8ds/mbIlzv4aX65btXgY4cqqeU4ba37rfKnc8tZ5hs99D8t KyKNZlwUveIsaoSvwniA6xLrBPuGr/y0rPh6FOkDs1MwwY3lsK8uguxLK1AfZY4r4lxhBs+F8+Sk4 XJJMltxTHw3FNWQ1tPP02xrKnrtIBIDj1w+AStmfvwcmOVrCmHRh0WK3DcEXvCzDpqfkfCuj9in5j X07pf753dOZ8NQ==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 45mg <45mg.writes@gmail.com> Subject: Re: [bug#74819] [PATCH v3] services: elogind: Support Hook Directories In-Reply-To: <1688c8ebd2c7d074edce3b27c0e439c5897ee251.1734524329.git.45mg.writes@gmail.com> (45mg.writes@gmail.com's message of "Wed, 18 Dec 2024 07:18:49 -0500") References: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> <1688c8ebd2c7d074edce3b27c0e439c5897ee251.1734524329.git.45mg.writes@gmail.com> Date: Mon, 23 Dec 2024 19:00:24 +0100 Message-ID: <874j2u8ekn.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74819 Cc: Simon Tournier , paren@disroot.org, Tobias Geerinckx-Rice , jgart , 74819@debbugs.gnu.org, Mathieu Othacehe , Christopher Baines X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, 45mg <45mg.writes@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: boo= lean) > +@item @code{allow-suspend-interrupts?} (default: @code{#f}) (type: boole= an) Write =E2=80=9C@itemx=E2=80=9D 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 =E2=80=9Celogind=E2=80=9D 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: b= oolean) =E2=80=9C@itemx=E2=80=9D as well. > +(define (/etc/elogind config) By convention, I=E2=80=99d call it =E2=80=98elogind-etc-directory=E2=80=99. > + #~(let ((sleep-dir (string-append #$output "/system-sleep/")) > + (shutdown-dir (string-append #$output "/system-shutdown/"))) > + (use-modules (guix build utils)) =E2=80=98use-modules=E2=80=99 should always be used at the top level; it=E2= =80=99s not guaranteed to work otherwise (it wouldn=E2=80=99t 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"= )) =E2=80=A6) Apart from these minor issues, the patch looks great to me. Could you send an updated version? Thanks! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 27 07:17:28 2024 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> To: 74819@debbugs.gnu.org Subject: [PATCH v4] services: elogind: Support Hook Directories 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-Debbugs-Cc: Ludovic Courtès , Maxim Cournoyer Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 Cc: 45mg <45mg.writes@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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 ;;; 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)))) base-commit: 3ada4796e9adcea6fce621e639ddbfb181ab6689 -- 2.47.1 From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 28 00:47:51 2024 Received: (at 74819) by debbugs.gnu.org; 28 Dec 2024 05:47:51 +0000 Received: from localhost ([127.0.0.1]:48401 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRPfy-0008PO-VJ for submit@debbugs.gnu.org; Sat, 28 Dec 2024 00:47:51 -0500 Received: from mail-pj1-f52.google.com ([209.85.216.52]:57759) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRPfx-0008PB-5Z for 74819@debbugs.gnu.org; Sat, 28 Dec 2024 00:47:49 -0500 Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2ee9a780de4so7185539a91.3 for <74819@debbugs.gnu.org>; Fri, 27 Dec 2024 21:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735364803; x=1735969603; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=ieS7i1szAbR7Dd6u3iltmXjTihP5tA9/4lBeKyvf9CE=; b=KVZ9S3rvQhofWA3lAv9svDKGvRJF0HnHJsPAtiAprorsxtq5F+c2OQV2X9nRNGdHJ4 xnjqaagWiFOgOgOe1HYvG+MEVvH1Ih2raNaLkcwg+fYzZEvRo6h1sgv2kjPwbO1MwC6b 29HPSsK4AbGwHZbQ8sK5OqxtqQf9zU9fCqnPE4lPbkdmb9kskgwMfpzBbA5W+aa6+IA8 TBBA625slGNp8Lu0dbOeaAhHyr7e/2zG2vP7DjeofVpAUmogs/6P89a4mWmzGDjIv5AP +UzmxFe1OwyOUNzO8y4Q7yFn7mzAzHz9N+RbqYvutMIWLkIjksLidwn26REW373DGBKy y/Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735364803; x=1735969603; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ieS7i1szAbR7Dd6u3iltmXjTihP5tA9/4lBeKyvf9CE=; b=Gl37a9GmA99CIf2KZNx6ad7r/GCRwrf5V8Q9CFcEFVBogVTVxB6rHB/3zAPp2erxjW 9F/M/Es/idsLlitQFJG9ewtiR/hCz0105pZ4w+7BvgIi9AwOrTsvcN8XZE97JOaFDRSP 9YwlAm/PhOQ5Aj8zslAmPufic1NUxSH5fE4rJ4qLCFArpXLeYP6eSvMR3WWLHA4+Xr8g hXCuWbXuNcGG+VUeI1m99sfQobxt/1je6whvk45LT2G/cQju9D2Nhn1PDhgR/ne1WoXe g207APbKvjN7YtMioG9/16s6qv3RDn90hL4GQyiwcmFCygvaXTmFRN3E3E963VBtxDbB Ls3w== X-Gm-Message-State: AOJu0Yym/D0uxS2aphV+yKwa10njkrJNuWwPogi0UMuGitzbiGIWJCmH OzGNUFqWNDzYUQb80wqsLaWQvNqKldtOBQwsgmg9de1yNQhc4ki+ X-Gm-Gg: ASbGncszG25xpeFdZhSFJkAEZWDGCCaNov8U+jD4HfbmxJYrneyRn9plZF48xJVURC6 xsdpUdBEJ7VT95ltoL7IZ3mGxx0stVf+2LnhjlBmgbZ4+GHMq2hpSJBtPmwk74lrdPEwqs0AaqA puqIGrqCAVbeg04e4kpgKsLegzEK/dX1n7T10fzn7ZenFSkz2ylyNC9uGi3VWV9VNdQmZNmeSKj fSDHKWk2ks53ok/DjM9+rSXTeXYIprvRDBkzXjcbRAI/ZGJ1cpxEw== X-Google-Smtp-Source: AGHT+IG7iUHGVg9QtUj0vii0p4Xfp82H3uk3zE0D+M+YxQlK798KB4rovG2/n0XDrv3DKAmc0zq85w== X-Received: by 2002:a05:6a00:4486:b0:727:d55e:4bee with SMTP id d2e1a72fcca58-72abdd4f493mr36162317b3a.1.1735364803454; Fri, 27 Dec 2024 21:46:43 -0800 (PST) Received: from terra ([2405:6586:be0:0:c8ff:1707:9b9:af89]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8dbae4sm15484154b3a.96.2024.12.27.21.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 21:46:42 -0800 (PST) From: Maxim Cournoyer To: 45mg <45mg.writes@gmail.com> Subject: Re: [bug#74819] [PATCH v4] services: elogind: Support Hook Directories In-Reply-To: <276103d4ae303592ff8ce4e83438e8c3d1c020bf.1735301702.git.45mg.writes@gmail.com> (45mg.writes@gmail.com's message of "Fri, 27 Dec 2024 07:15:02 -0500") References: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> <276103d4ae303592ff8ce4e83438e8c3d1c020bf.1735301702.git.45mg.writes@gmail.com> Date: Sat, 28 Dec 2024 14:46:33 +0900 Message-ID: <87frm8tl52.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74819 Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , 74819@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi, 45mg <45mg.writes@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 -- Thanks, Maxim From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 30 06:27:17 2024 Received: (at 74819-done) by debbugs.gnu.org; 30 Dec 2024 11:27:18 +0000 Received: from localhost ([127.0.0.1]:57532 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tSDvZ-0003hM-ML for submit@debbugs.gnu.org; Mon, 30 Dec 2024 06:27:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33290) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tSDvX-0003h3-QK for 74819-done@debbugs.gnu.org; Mon, 30 Dec 2024 06:27:16 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tSDvS-0005tr-Ig; Mon, 30 Dec 2024 06:27:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=nSFXeLUwk6cqtDukIiCeRDwzB/oA5mO5fRe2Ph8fal8=; b=HJKZCwz25Q0F1ls1OqyI ncXX2UzRCk75+x/hkBglig+NbwmPtXHPwok6FZknokhEkJEA6ktBibb4kah5fuwxI4qC5sOEa+4e9 u4C9whOGjNQMZu101incMQ2eCatyYl4xM5p+nzRW2sHtKQG1262ExLZf0UbKfy2Kvyi0IytmcpK3l piyqq6y+9m3XF4/4zVOAmFL9LM9F12VfaLxn3Gojx7+cFAmfey1zyA841/YWC5EXt+QhkUwIAj4U2 +BW0BwSqvjbwSoyMym9BOFoaFqAzI+dAj01j4c5kwxMPuT+24KT9GmGBZOme+ZB6Dj4LVCPwPgz9Y 9hRwYfrd9rCbcw==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 45mg <45mg.writes@gmail.com> Subject: Re: [bug#74819] [PATCH v4] services: elogind: Support Hook Directories In-Reply-To: <276103d4ae303592ff8ce4e83438e8c3d1c020bf.1735301702.git.45mg.writes@gmail.com> (45mg.writes@gmail.com's message of "Fri, 27 Dec 2024 07:15:02 -0500") References: <7286c9dd75c4853f5811720150c027b9d9b511d7.1734003226.git.45mg.writes@gmail.com> <276103d4ae303592ff8ce4e83438e8c3d1c020bf.1735301702.git.45mg.writes@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Date: Mon, 30 Dec 2024 12:26:43 +0100 Message-ID: <87msgdtnrg.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74819-done Cc: Maxim Cournoyer , 74819-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello, 45mg <45mg.writes@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=E2=80=99. From unknown Sat Sep 20 23:20:38 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 27 Jan 2025 12:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator