;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Mathieu Othacehe ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu services pm) #:use-module (guix gexp) #:use-module (guix packages) #:use-module (guix records) #:use-module (gnu packages admin) #:use-module (gnu packages linux) #:use-module (gnu services) #:use-module (gnu services base) #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:use-module (gnu system shadow) #:export (tlp-service-type tlp-configuration thermald-configuration thermald-service-type)) (define (uglify-field-name field-name) (let ((str (symbol->string field-name))) (string-join (string-split (string-upcase (if (string-suffix? "?" str) (substring str 0 (1- (string-length str))) str)) #\-) "_"))) (define (serialize-field field-name val) (format #t "~a=~a\n" (uglify-field-name field-name) val)) (define (serialize-boolean field-name val) (serialize-field field-name (if val "1" "0"))) (define-maybe boolean) (define (serialize-string field-name val) (serialize-field field-name val)) (define-maybe string) (define (space-separated-string-list? val) (and (list? val) (and-map (lambda (x) (and (string? x) (not (string-index x #\space)))) val))) (define (serialize-space-separated-string-list field-name val) (serialize-field field-name (format #f "~s" (string-join val " ")))) (define-maybe space-separated-string-list) (define (non-negative-integer? val) (and (exact-integer? val) (not (negative? val)))) (define (serialize-non-negative-integer field-name val) (serialize-field field-name val)) (define-maybe non-negative-integer) (define (on-off-boolean? val) (boolean? val)) (define (serialize-on-off-boolean field-name val) (serialize-field field-name (if val "on" "off"))) (define-maybe on-off-boolean) (define (y-n-boolean? val) (boolean? val)) (define (serialize-y-n-boolean field-name val) (serialize-field field-name (if val "Y" "N"))) (define-configuration tlp-configuration (tlp (package tlp) "The TLP package.") (tlp-enable? (boolean #t) "Set to true if you wish to enable TLP.") (tlp-default-mode (string "AC") "Default mode when no power supply can be detected. Alternatives are AC and BAT.") (disk-idle-secs-on-ac (non-negative-integer 0) "Number of seconds Linux kernel has to wait after the disk goes idle, before syncing on AC.") (disk-idle-secs-on-bat (non-negative-integer 2) "Same as @code{disk-idle-ac} but on BAT mode.") (max-lost-work-secs-on-ac (non-negative-integer 15) "Dirty pages flushing periodicity, expressed in seconds.") (max-lost-work-secs-on-bat (non-negative-integer 60) "Same as @code{max-lost-work-secs-on-ac} but on BAT mode.") (cpu-scaling-governor-on-ac (maybe-space-separated-string-list 'disabled) "CPU frequency scaling governor on AC mode. With intel_pstate driver, alternatives are powersave and performance. With acpi-cpufreq driver, alternatives are ondemand, powersave, performance and conservative.") (cpu-scaling-governor-on-bat (maybe-space-separated-string-list 'disabled) "Same as @code{cpu-scaling-governor-on-ac} but on BAT mode.") (cpu-scaling-min-freq-on-ac (maybe-non-negative-integer 'disabled) "Set the min available frequency for the scaling governor on AC.") (cpu-scaling-max-freq-on-ac (maybe-non-negative-integer 'disabled) "Set the max available frequency for the scaling governor on AC.") (cpu-scaling-min-freq-on-bat (maybe-non-negative-integer 'disabled) "Set the min available frequency for the scaling governor on BAT.") (cpu-scaling-max-freq-on-bat (maybe-non-negative-integer 'disabled) "Set the max available frequency for the scaling governor on BAT.") (cpu-min-perf-on-ac (maybe-non-negative-integer 'disabled) "Limit the min P-state to control the power dissipation of the CPU, in AC mode. Values are stated as a percentage of the available performance.") (cpu-max-perf-on-ac (maybe-non-negative-integer 'disabled) "Limit the max P-state to control the power dissipation of the CPU, in AC mode. Values are stated as a percentage of the available performance.") (cpu-min-perf-on-bat (maybe-non-negative-integer 'disabled) "Same as @code{cpu-min-perf-on-ac} on BAT mode.") (cpu-max-perf-on-bat (maybe-non-negative-integer 'disabled) "Same as @code{cpu-max-perf-on-ac} on BAT mode.") (cpu-boost-on-ac? (maybe-boolean 'disabled) "Enable CPU turbo boost feature on AC mode.") (cpu-boost-on-bat? (maybe-boolean 'disabled) "Same as @code{cpu-boost-on-ac?} on BAT mode.") (sched-powersave-on-ac? (boolean #f) "Allow Linux kernel to minimize the number of CPU cores/hyper-threads used under light load conditions.") (sched-powersave-on-bat? (boolean #t) "Same as @code{sched-powersave-on-ac?} but on BAT mode.") (nmi-watchdog? (boolean #f) "Enable Linux kernel NMI watchdog.") (phc-controls (maybe-string 'disabled) "For Linux kernels with PHC patch applied, change CPU voltages. An example value would be @samp{\"F:V F:V F:V F:V\"}.") (energy-perf-policy-on-ac (string "performance") "Set CPU performance versus energy saving policy on AC. Alternatives are performance, normal, powersave.")