[PATCH] services: Add thinkfan service.

  • Open
  • quality assurance status badge
Details
2 participants
  • Josselin Poiret
  • lgcoelho
Owner
unassigned
Submitted by
lgcoelho
Severity
normal
L
L
lgcoelho wrote on 24 Dec 2023 19:53
(address . guix-patches@gnu.org)
29b6707c8c4cdf1808edc79813215578@disroot.org
This patch add thinkfan-service-type to (gnu services pm).
Attachment: file
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(-)

Toggle diff (76 lines)
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
L
L
lgcoelho wrote on 26 Dec 2023 00:59
[PATCH] thinkfan-service-type: Place config-file in /etc/thinkfan.conf if file-like
(address . 68012@debbugs.gnu.org)
1e749af5b479cbc13f70c2ce64121682@disroot.org
Attachment: file
From 0160f08bb315ee297b0ad8b861f9e3b5bd7eedfb Mon Sep 17 00:00:00 2001
From: Luis Guilherme Coelho <lgcoelho@disroot.org>
Date: Mon, 25 Dec 2023 20:48:35 -0300
Subject: [PATCH 2/2] thinkfan-service-type: Place config-file in
/etc/thinkfan.conf if file-like

---
gnu/services/pm.scm | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

Toggle diff (51 lines)
diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index baded5c43e..2d02476d20 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -470,12 +470,16 @@ (define thermald-service-type
(description "Run thermald, a CPU frequency scaling service that helps
prevent overheating.")))
+(define (string-or-file-like? x)
+ (or (string? x)
+ (file-like? x)))
+
(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")
+ (string-or-file-like "/etc/thinkfan.conf")
"Configuration file to use.")
(log-file
(string "/var/log/thinkfan.log")
@@ -511,15 +515,25 @@ (define thinkfan-modprobe-config
(define (thinkfan-modprobe-etc-service config)
`(("modprobe.d/thinkfan.conf" ,thinkfan-modprobe-config)))
+(define thinkfan-activation
+ (match-record-lambda <thinkfan-configuration>
+ (config-file)
+ (when (file-like? config-file)
+ (with-imported-modules '((guix build utils))
+ #~(begin
+ (use-modules (guix build utils))
+ (copy-file #$config-file "/etc/thinkfan.conf"))))))
+
(define thinkfan-service-type
(service-type
(name 'thinkfan)
(extensions
(list (service-extension shepherd-root-service-type
thinkfan-shepherd-service)
+ (service-extension activation-service-type
+ thinkfan-activation)
(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
L
L
lgcoelho wrote on 27 Dec 2023 18:04
[PATCH] thinkfan-service-type: Add thinkfan entry to thinkfan-configuration.
(address . 68012@debbugs.gnu.org)
ed8a1cc6dad7fa297e3ce08171cad361@disroot.org
Attachment: file
From ff38662f5d5512b2f656cd3daed9c3ee32cd60ae Mon Sep 17 00:00:00 2001
From: Luis Guilherme Coelho <lgcoelho@disroot.org>
Date: Wed, 27 Dec 2023 14:02:04 -0300
Subject: [PATCH 3/3] thinkfan-service-type: Add thinkfan entry to
thinkfan-configuration

---
gnu/services/pm.scm | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

Toggle diff (38 lines)
diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 2d02476d20..5b96d4265a 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -475,6 +475,9 @@ (define (string-or-file-like? x)
(file-like? x)))
(define-configuration/no-serialization thinkfan-configuration
+ (thinkfan
+ (package thinkfan)
+ "Thinkfan package to be used.")
(pid-file
(string "/var/run/thinkfan.pid")
"Where to store the PID file.")
@@ -491,17 +494,16 @@ (define-configuration/no-serialization thinkfan-configuration
(define thinkfan-shepherd-service
(match-record-lambda <thinkfan-configuration>
- (pid-file config-file log-file extra-options)
+ (thinkfan 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)
+ (list (string-append #$thinkfan "/sbin/thinkfan")
+ "-n" #$@extra-options
+ "-c" #$config-file)
#:log-file #$log-file
#:pid-file #$pid-file))
(stop #~(make-kill-destructor))
--
2.41.0
J
J
Josselin Poiret wrote on 13 Jan 17:29 +0100
Re: [bug#68012] [PATCH] services: Add thinkfan service.
87le8tgpt7.fsf@jpoiret.xyz
Hi Luis,

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

Toggle quote (8 lines)
> 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].

Toggle quote (4 lines)
> + (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.

--
Josselin Poiret
-----BEGIN PGP SIGNATURE-----

iQHEBAEBCAAuFiEEOSSM2EHGPMM23K8vUF5AuRYXGooFAmWiulQQHGRldkBqcG9p
cmV0Lnh5egAKCRBQXkC5Fhcaii7CDACsi3Bsxw0EF629tnq/YqxXEwdzaccesZFn
ZYH+7YWBUSP78EF3kYmQ63QVRtZKrPdC2hUbjZOa0UcYl1DX6je4YQLKVWxKIsHu
N4r+2T1J+vZBuSnAQcJALKEqtBrR23sh33BwTXphvlma2uGhEvXHAZxC7snG2Cei
WzduBjPBhGD6ZwpCcE2/o9nKxsYY7dOXay2ta6gPIzNPf1GewYHXhLs4n7XcUGqq
cbGUwIt/YBhuL0Lobr8drQZ+mccBayGpv7iNHfpF3Wa/hWUyGmdzyl4UOZRz4jXa
AXfhXG/NIg3zdFg8jeTnFjl+x3JrNh5m4wpzxRkF8PPY/oP9JbTZbefobr5iE3t8
4FtlBAHoxrYGJd4b26VrSiL1hJaiG8GyEgtVpaI5JpW1CpX8I2zKrv+MAH57IohR
drHRm8MB3zrYe469oEQKMftBNBEp56LDTsCJOz1C74aMV3TjNWqpv4pGOByjFCe1
9cMqqKixuil5aqiGq8frENfHWE1JaqM=
=bTt1
-----END PGP SIGNATURE-----

J
J
Josselin Poiret wrote on 13 Jan 17:30 +0100
Re: [bug#68012] [PATCH] thinkfan-service-type: Place config-file in /etc/thinkfan.conf if file-like
87il3xgpr4.fsf@jpoiret.xyz
lgcoelho--- via Guix-patches via <guix-patches@gnu.org> writes:

Toggle quote (10 lines)
> +(define thinkfan-activation
> + (match-record-lambda <thinkfan-configuration>
> + (config-file)
> + (when (file-like? config-file)
> + (with-imported-modules '((guix build utils))
> + #~(begin
> + (use-modules (guix build utils))
> + (copy-file #$config-file "/etc/thinkfan.conf"))))))
> +

This is not needed as you already specify the config file to use to
thinkfan with the -c option.

--
Josselin Poiret
-----BEGIN PGP SIGNATURE-----

iQHEBAEBCAAuFiEEOSSM2EHGPMM23K8vUF5AuRYXGooFAmWiup8QHGRldkBqcG9p
cmV0Lnh5egAKCRBQXkC5FhcaikEdDAC1tZEvvdNd17a1P1MtuD2Rpdwqr3a1K1+/
dfDr0toTl5jdKKETvSizyegq+TJUd1oB6VmkTWuAVNBOxVyxc37YVpchlFj1xDR9
FzcnFSpMNsYd/jKDJq8tsNSVLsJAjNoj5Ll9kAK/giC4XplM3eMmX6LlsOlfGUdE
ZtwJek7ydn1xQLPJajPqrSORaKlduX3g8aqakzDOw8l5lLGfxpQVA9RnGvGJGDSe
rzo0+X3hU5Jjvfu30fRqte2wMXqkYMHqRwsWb7NIVW4fbFzEXXfwpy9pEL6aJGIH
hRU4wrn1pkOgwbuYmI9XwUaS1m6SXma/DfTKfkCNu9//nX4xTGreSqtK77riA4xs
0Ps3p81ZmR13GDKyfk8ZXHMVL8Vhmzia9NZGH5gGaCChW6Dzu7CRwWglTekF9bnH
0kC5vIIey0VR0tff/FAl/9dXa95Tsrbp/T7nSliRP0HjT/gkhJ1HV+PI75YDtyNz
pc6Z6KoTLP/Zrss78jmNRsvtdQWu3cM=
=uugY
-----END PGP SIGNATURE-----

J
J
Josselin Poiret wrote on 13 Jan 17:31 +0100
Re: [bug#68012] [PATCH] thinkfan-service-type: Add thinkfan entry to thinkfan-configuration.
87frz1gpoh.fsf@jpoiret.xyz
lgcoelho--- via Guix-patches via <guix-patches@gnu.org> writes:

Toggle quote (27 lines)
> (define-configuration/no-serialization thinkfan-configuration
> + (thinkfan
> + (package thinkfan)
> + "Thinkfan package to be used.")
> (pid-file
> (string "/var/run/thinkfan.pid")
> "Where to store the PID file.")
> @@ -491,17 +494,16 @@ (define-configuration/no-serialization thinkfan-configuration
>
> (define thinkfan-shepherd-service
> (match-record-lambda <thinkfan-configuration>
> - (pid-file config-file log-file extra-options)
> + (thinkfan 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)
> + (list (string-append #$thinkfan "/sbin/thinkfan")
> + "-n" #$@extra-options
> + "-c" #$config-file)

That's a good idea, but can you squash this with the first commit?

Best,
--
Josselin Poiret
-----BEGIN PGP SIGNATURE-----

iQHEBAEBCAAuFiEEOSSM2EHGPMM23K8vUF5AuRYXGooFAmWiuv4QHGRldkBqcG9p
cmV0Lnh5egAKCRBQXkC5Fhcaii7sDAClUmXNm5DZ3VjtMgsJFIw5Vs9So6uyPAsL
j8H3mafreF1NVOHpcsKLXSaGYYIa2Lf/EvrFNDEpBI6FautYtZ54zNlU0kX50muR
wWoVWg527wjuYDRlzhMXv65QK9TVVAof7vz2DHwdznk/fZQR9RspaK4wHbCKQwmJ
N5DthLUf6Jh2YPlAxPoC/saBVU7l4w5MLB/hqB7Eh5OyxhARZKWozUQucMnZnvdh
sQVvJ7rwJE7pPdU78gFuFOJm3UdxFeeYbf1IS5xkZUtGJHs90oeHBuoba8YsfJPV
76NeGULEneir4+OtxzzdJrO/MpgiMgQlM+AIsSmIPAD80fjoQ01lpzZqptLipxCV
5QUhKeGrBpTaXAlasCayfpXdsU00/uc5FqX3kGOW0Gy7b9xCQGCbAZQVR5rkvM2u
1pkEKkk8XLCixbZOnRZPa7yj2UIF9xBrwJ8YctemmB7+hRHA0kIZU9Vl1mbH8nKN
LQPLlRHpoVmzz4ka2vSFIcPxl14mrO8=
=q88x
-----END PGP SIGNATURE-----

?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 68012@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 68012
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch