From 04c1389930a164c9dfca9418858e7ff35ff2e470 Mon Sep 17 00:00:00 2001 From: anemofilia Date: Fri, 24 Nov 2023 01:35:17 -0300 Subject: [PATCH] services: linux: Minor improvements for thinkfan-service --- modules/radix/services/linux.scm | 67 ++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/modules/radix/services/linux.scm b/modules/radix/services/linux.scm index 1693734..f9460da 100644 --- a/modules/radix/services/linux.scm +++ b/modules/radix/services/linux.scm @@ -1,61 +1,70 @@ (define-module (radix services linux) - #:use-module (gnu) #:use-module (radix packages linux) + #:use-module (gnu) #:use-module (gnu services) #:use-module (gnu services shepherd) + #:use-module (gnu services configuration) #:use-module (guix gexp) #:use-module (guix records) + #:use-module (ice-9 curried-definitions) #:export (thinkfan-configuration make-thinkfan-configuration thinkfan-configuration? - thinkfan-configuration-requirement thinkfan-configuration-pid-file thinkfan-configuration-config-file thinkfan-configuration-log-file - thinkfan-configuration-respawn thinkfan-configuration-extra-options thinkfan-shepherd-service thinkfan-service-type)) -(define-record-type* - thinkfan-configuration make-thinkfan-configuration - thinkfan-configuration? - (requirement thinkfan-configuration-requirement ; list of symbols - (default '(user-processes))) - (pid-file thinkfan-configuration-pid-file ; string - (default "/var/run/thinkfan.pid")) - (config-file thinkfan-configuration-config-file ; string - (default "/etc/thinkfan.conf")) - (log-file thinkfan-configuration-log-file ; string - (default "/var/log/thinkfan.log")) - (respawn? thinkfan-configuration-respawn? ; boolean - (default #t)) - (extra-options thinkfan-configuration-extra-options ; list of strings - (default '()))) +(define ((list-of predicate) x) + (null? (filter (negate predicate) x))) -(define (thinkfan-shepherd-service config) - (match-record config - (requirement pid-file config-file log-file respawn? extra-options) +(define list-of-symbols? + (list-of symbol?)) + +(define list-of-strings? + (list-of string?)) + +(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 + (pid-file config-file log-file extra-options) (list (shepherd-service (provision '(thinkfan)) (documentation "Adjust fan level according to configured temperature limits.") - (requirement requirement) + (requirement '(user-processes kernel-module-loader)) (start #~(make-forkexec-constructor - (list (string-append #$thinkfan-next "/sbin/thinkfan") - (string-append "-c" #$config-file) - #$@extra-options) - #:pid-file #$pid-file - #:log-file #$log-file)) + (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? respawn?))))) + (respawn? #t))))) (define thinkfan-modprobe-config (plain-file "thinkfan.conf" - "options thinkpad_acpi experimental=1 fan_control=1")) + "options thinkpad_acpi experimental=1 fan_control=1")) (define (thinkfan-modprobe-etc-service config) `(("modprobe.d/thinkfan.conf" ,thinkfan-modprobe-config)))