services: linux: Minor improvements for thinkfan-service

pull/1/head
anemofilia 2023-11-24 01:35:17 -03:00 committed by Luis Guilherme Coelho
parent b5daac8464
commit 04c1389930
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 38 additions and 29 deletions

View File

@ -1,57 +1,66 @@
(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>
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 <thinkfan-configuration>
(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 <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 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"