Subject: [PATCH] thinkfan-service-type: Place config-file in /etc/thinkfan.conf if file-like

From: [email-masked]
Date: Mon, 25 Dec 2023 23:59:54 +0000

From 0160f08bb315ee297b0ad8b861f9e3b5bd7eedfb Mon Sep 17 00:00:00 2001
From: Luis Guilherme Coelho <[email-masked]>
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(-)

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