diff mbox series

[bug#68012] services: Add thinkfan service.

Message ID 29b6707c8c4cdf1808edc79813215578@disroot.org
State New
Headers show
Series [bug#68012] services: Add thinkfan service. | expand

Commit Message

Deslauriers, Douglas via Guix-patches" via Dec. 24, 2023, 6:53 p.m. UTC
This patch add thinkfan-service-type to (gnu services pm).

Comments

Josselin Poiret Jan. 13, 2024, 4:29 p.m. UTC | #1
Hi Luis,

lgcoelho--- via Guix-patches via <guix-patches@gnu.org> writes:

> This patch add thinkfan-service-type to (gnu services pm).
> From 92bf99099f91c0f1dae71b0cf9e5f8e6799a3679 Mon Sep 17 00:00:00 2001
> From: Luis Guilherme Coelho <lgcoelho@disroot.org>
> Date: Sun, 24 Dec 2023 15:52:04 -0300
> Subject: [PATCH] services: Add thinkfan service.
>
> ---

Please add a commit message following the ChangeLog convention.  You can
take inspiration from other commits in the repo, and read up on it at [0].

> +  (config-file
> +   (string "/etc/thinkfan.conf")
> +   "Configuration file to use.")

This should not refer to an absolute path.  Please use a file-like
instead, users can still use (local-file ...) to give external files.

[0] https://www.gnu.org/prep/standards/html_node/Change-Logs.html
diff mbox series

Patch

From 92bf99099f91c0f1dae71b0cf9e5f8e6799a3679 Mon Sep 17 00:00:00 2001
From: Luis Guilherme Coelho <lgcoelho@disroot.org>
Date: Sun, 24 Dec 2023 15:52:04 -0300
Subject: [PATCH] services: Add thinkfan service.

---
 gnu/services/pm.scm | 59 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 3daf484cc1..baded5c43e 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -31,7 +31,10 @@  (define-module (gnu services pm)
             tlp-configuration
 
             thermald-configuration
-            thermald-service-type))
+            thermald-service-type
+
+            thinkfan-configuration
+            thinkfan-service-type))
 
 (define (uglify-field-name field-name)
   (let ((str (symbol->string field-name)))
@@ -466,3 +469,57 @@  (define thermald-service-type
    (default-value (thermald-configuration))
    (description "Run thermald, a CPU frequency scaling service that helps
 prevent overheating.")))
+
+(define-configuration/no-serialization thinkfan-configuration
+  (pid-file
+   (string "/var/run/thinkfan.pid")
+   "Where to store the PID file.")
+  (config-file
+   (string "/etc/thinkfan.conf")
+   "Configuration file to use.")
+  (log-file
+   (string "/var/log/thinkfan.log")
+    "File where ‘thinkfan’ writes its log to.")
+  (extra-options
+   (list-of-strings '())
+   "This option provides an “escape hatch” for the user to provide
+arbitrary command-line arguments to ‘thinkfan’ as a list of strings."))
+
+(define thinkfan-shepherd-service
+  (match-record-lambda <thinkfan-configuration>
+    (pid-file config-file log-file extra-options)
+    (list (shepherd-service
+           (provision '(thinkfan))
+           (documentation
+            "Adjust fan level according to configured temperature limits.")
+           (requirement '(user-processes))
+           (start #~(make-forkexec-constructor
+                      (list (string-append #$thinkfan-next
+                                           "/sbin/thinkfan")
+                             "-n" #$@extra-options
+                             "-c" #$config-file)
+                     #:log-file #$log-file
+                     #:pid-file #$pid-file))
+           (stop #~(make-kill-destructor))
+           (one-shot? #t)
+           (respawn? #t)))))
+
+(define thinkfan-modprobe-config
+  (plain-file "thinkfan.conf"
+              "options thinkpad_acpi experimental=1 fan_control=1"))
+
+(define (thinkfan-modprobe-etc-service config)
+  `(("modprobe.d/thinkfan.conf" ,thinkfan-modprobe-config)))
+
+(define thinkfan-service-type
+  (service-type
+   (name 'thinkfan)
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             thinkfan-shepherd-service)
+          (service-extension etc-service-type
+                             thinkfan-modprobe-etc-service)))
+  (default-value (thinkfan-configuration))
+  (description
+   "Adjust fan level according to configured temperature limits.")))
+
-- 
2.41.0