From f1e900a3b8267846eb3909fbf86e681cbc56203d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 23 Mar 2017 14:00:29 +0100 Subject: doc: Document 'guix-publish-service-type' instead of 'guix-publish-service'. * doc/guix.texi (Base Services): Document 'guix-publish-service-type' and 'guix-configuration'. Remove 'guix-publish-service'. (Invoking guix publish): Mention 'guix-publish-service-type'. * gnu/services/base.scm (guix-publish-service): Mark as deprecated. (): Export getters. --- doc/guix.texi | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index b57e219562..b452b087f1 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6551,9 +6551,9 @@ primarily for debugging a running @command{guix publish} server. @end table Enabling @command{guix publish} on a GuixSD system is a one-liner: just -add a call to @code{guix-publish-service} in the @code{services} field -of the @code{operating-system} declaration (@pxref{guix-publish-service, -@code{guix-publish-service}}). +instantiate a @code{guix-publish-service-type} service in the @code{services} field +of the @code{operating-system} declaration (@pxref{guix-publish-service-type, +@code{guix-publish-service-type}}). If you are instead running Guix on a ``foreign distro'', follow these instructions:” @@ -9007,17 +9007,34 @@ uses the @code{ps2} protocol, which works for both USB and PS/2 mice. This service is not part of @var{%base-services}. @end deffn -@anchor{guix-publish-service} -@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @ - [#:port 80] [#:host "localhost"] -Return a service that runs @command{guix publish} listening on @var{host} -and @var{port} (@pxref{Invoking guix publish}). +@anchor{guix-publish-service-type} +@deffn {Scheme Variable} guix-publish-service-type @var{config} +This is the service type for @command{guix publish} (@pxref{Invoking +guix publish}). @var{config} must be a @code{guix-configuration} +object, as described below. This assumes that @file{/etc/guix} already contains a signing key pair as created by @command{guix archive --generate-key} (@pxref{Invoking guix archive}). If that is not the case, the service will fail to start. @end deffn +@deftp {Data Type} guix-publish-configuration +Data type representing the configuration of the @code{guix publish} +service. + +@table @asis +@item @code{guix} (default: @code{guix}) +The Guix package to use. + +@item @code{port} (default: @code{80}) +The TCP port to listen for connections. + +@item @code{host} (default: @code{"localhost"}) +The host (and thus, network interface) to listen to. Use +@code{"0.0.0.0"} to listen on all the network interfaces. +@end table +@end deftp + @anchor{rngd-service} @deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @ [#:device "/dev/hwrng"] -- cgit v1.2.3 From 697ddb8850d7aeb612ec9402e86f82c44edf8c96 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 23 Mar 2017 14:07:00 +0100 Subject: services: guix-publish: Add 'compression-level' and 'nar-path' fields. * gnu/services/base.scm ()[compression-level, nar-path]: New fields. (guix-publish-shepherd-service): Honor them. * doc/guix.texi (Base Services): Document them. --- doc/guix.texi | 9 +++++++++ gnu/services/base.scm | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index b452b087f1..fb0862096a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9032,6 +9032,15 @@ The TCP port to listen for connections. @item @code{host} (default: @code{"localhost"}) The host (and thus, network interface) to listen to. Use @code{"0.0.0.0"} to listen on all the network interfaces. + +@item @code{compression-level} (default: @code{3}) +The gzip compression level at which substitutes are compressed. Use +@code{0} to disable compression altogether, and @code{9} to get the best +compression ratio at the expense of increased CPU usage. + +@item @code{nar-path} (default: @code{"nar"}) +The URL path at which ``nars'' can be fetched. @xref{Invoking guix +publish, @code{--nar-path}}, for details. @end table @end deftp diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 0de83f36c8..95a1ba2a6c 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -127,6 +127,8 @@ guix-publish-configuration-guix guix-publish-configuration-port guix-publish-configuration-host + guix-publish-configuration-compression-level + guix-publish-configuration-nar-path guix-publish-service guix-publish-service-type @@ -1438,11 +1440,15 @@ failed to register hydra.gnu.org public key: ~a~%" status)))))))) (port guix-publish-configuration-port ;number (default 80)) (host guix-publish-configuration-host ;string - (default "localhost"))) + (default "localhost")) + (compression-level guix-publish-compression-level ;integer + (default 3)) + (nar-path guix-publish-nar-path ;string + (default "nar"))) (define guix-publish-shepherd-service (match-lambda - (($ guix port host) + (($ guix port host compression nar-path) (list (shepherd-service (provision '(guix-publish)) (requirement '(guix-daemon)) @@ -1450,6 +1456,8 @@ failed to register hydra.gnu.org public key: ~a~%" status)))))))) (list #$(file-append guix "/bin/guix") "publish" "-u" "guix-publish" "-p" #$(number->string port) + "-C" #$(number->string compression) + (string-append "--nar-path=" #$nar-path) (string-append "--listen=" #$host)))) (stop #~(make-kill-destructor))))))) -- cgit v1.2.3 From bfbf6e1e1009cc2697b38d6c7ea2ebdd9db627f6 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Fri, 24 Mar 2017 11:00:15 +0100 Subject: gnu: Add tlp service. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/services/pm.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add gnu/services/tlp.scm. * doc/guix.texi (Power management Services): New section. Signed-off-by: Clément Lassieur --- doc/guix.texi | 505 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 2 + gnu/services/pm.scm | 404 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 911 insertions(+) create mode 100644 gnu/services/pm.scm (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index fb0862096a..5649b089c2 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -216,6 +216,7 @@ Services * VPN Services:: VPN daemons. * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. +* Power management Services:: The TLP tool. * Miscellaneous Services:: Other services. Defining Services @@ -8451,6 +8452,7 @@ declaration. * VPN Services:: VPN daemons. * Network File System:: NFS related services. * Continuous Integration:: The Cuirass service. +* Power management Services:: The TLP tool. * Miscellaneous Services:: Other services. @end menu @@ -13708,6 +13710,509 @@ The Cuirass package to use. @end table @end deftp +@node Power management Services +@subsubsection Power management Services + +@cindex power management with TLP +The @code{(gnu services pm)} module provides a Guix service definition +for the Linux power management tool TLP. + +TLP enables various powersaving modes in userspace and kernel. +Contrary to @code{upower-service}, it is not a passive, +monitoring tool, as it will apply custom settings each time a new power +source is detected. More information can be found at +@uref{http://linrunner.de/en/tlp/tlp.html, TLP home page}. + +@deffn {Scheme Variable} tlp-service-type +The service type for the TLP tool. Its value should be a valid +TLP configuration (see below). For example: +@example +(service tlp-service-type (tlp-configuration)) +@end example +@end deffn + +By default TLP does not need much configuration but most TLP parameters +can be tweaked using @code{tlp-configuration}. + +Each parameter definition is preceded by its type; for example, +@samp{boolean foo} indicates that the @code{foo} parameter +should be specified as a boolean. Types starting with +@code{maybe-} denote parameters that won't show up in TLP config file +when their value is @code{'disabled}. + +@c The following documentation was initially generated by +@c (generate-tlp-documentation) in (gnu services pm). Manually maintained +@c documentation is better, so we shouldn't hesitate to edit below as +@c needed. However if the change you want to make to this documentation +@c can be done in an automated way, it's probably easier to change +@c (generate-documentation) than to make it below and have to deal with +@c the churn as TLP updates. + +Available @code{tlp-configuration} fields are: + +@deftypevr {@code{tlp-configuration} parameter} package tlp +The TLP package. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean tlp-enable? +Set to true if you wish to enable TLP. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string tlp-default-mode +Default mode when no power supply can be detected. Alternatives are AC +and BAT. + +Defaults to @samp{"AC"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-ac +Number of seconds Linux kernel has to wait after the disk goes idle, +before syncing on AC. + +Defaults to @samp{0}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer disk-idle-secs-on-bat +Same as @code{disk-idle-ac} but on BAT mode. + +Defaults to @samp{2}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-ac +Dirty pages flushing periodicity, expressed in seconds. + +Defaults to @samp{15}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer max-lost-work-secs-on-bat +Same as @code{max-lost-work-secs-on-ac} but on BAT mode. + +Defaults to @samp{60}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-ac +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. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list cpu-scaling-governor-on-bat +Same as @code{cpu-scaling-governor-on-ac} but on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-ac +Set the min available frequency for the scaling governor on AC. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-ac +Set the max available frequency for the scaling governor on AC. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-min-freq-on-bat +Set the min available frequency for the scaling governor on BAT. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-scaling-max-freq-on-bat +Set the max available frequency for the scaling governor on BAT. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-ac +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. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-ac +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. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-min-perf-on-bat +Same as @code{cpu-min-perf-on-ac} on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-non-negative-integer cpu-max-perf-on-bat +Same as @code{cpu-max-perf-on-ac} on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-ac? +Enable CPU turbo boost feature on AC mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-boolean cpu-boost-on-bat? +Same as @code{cpu-boost-on-ac?} on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-ac? +Allow Linux kernel to minimize the number of CPU cores/hyper-threads +used under light load conditions. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean sched-powersave-on-bat? +Same as @code{sched-powersave-on-ac?} but on BAT mode. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean nmi-watchdog? +Enable Linux kernel NMI watchdog. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-string phc-controls +For Linux kernels with PHC patch applied, change CPU voltages. An +example value would be @samp{"F:V F:V F:V F:V"}. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-ac +Set CPU performance versus energy saving policy on AC. Alternatives are +performance, normal, powersave. + +Defaults to @samp{"performance"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string energy-perf-policy-on-bat +Same as @code{energy-perf-policy-ac} but on BAT mode. + +Defaults to @samp{"powersave"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disks-devices +Hard disk devices. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-ac +Hard disk advanced power management level. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list disk-apm-level-on-bat +Same as @code{disk-apm-bat} but on BAT mode. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-ac +Hard disk spin down timeout. One value has to be specified for each +declared hard disk. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-spindown-timeout-on-bat +Same as @code{disk-spindown-timeout-on-ac} but on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list disk-iosched +Select IO scheduler for disk devices. One value has to be specified for +each declared hard disk. Example alternatives are cfq, deadline and +noop. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-ac +SATA aggressive link power management (ALPM) level. Alternatives are +min_power, medium_power, max_performance. + +Defaults to @samp{"max_performance"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string sata-linkpwr-on-bat +Same as @code{sata-linkpwr-ac} but on BAT mode. + +Defaults to @samp{"min_power"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-string sata-linkpwr-blacklist +Exclude specified SATA host devices for link power management. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-ac? +Enable Runtime Power Management for AHCI controller and disks on AC +mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-on-off-boolean ahci-runtime-pm-on-bat? +Same as @code{ahci-runtime-pm-on-ac} on BAT mode. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer ahci-runtime-pm-timeout +Seconds of inactivity before disk is suspended. + +Defaults to @samp{15}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-ac +PCI Express Active State Power Management level. Alternatives are +default, performance, powersave. + +Defaults to @samp{"performance"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string pcie-aspm-on-bat +Same as @code{pcie-aspm-ac} but on BAT mode. + +Defaults to @samp{"powersave"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-ac +Radeon graphics clock speed level. Alternatives are low, mid, high, +auto, default. + +Defaults to @samp{"high"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-power-profile-on-bat +Same as @code{radeon-power-ac} but on BAT mode. + +Defaults to @samp{"low"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-ac +Radeon dynamic power management method (DPM). Alternatives are battery, +performance. + +Defaults to @samp{"performance"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-state-on-bat +Same as @code{radeon-dpm-state-ac} but on BAT mode. + +Defaults to @samp{"battery"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-ac +Radeon DPM performance level. Alternatives are auto, low, high. + +Defaults to @samp{"auto"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string radeon-dpm-perf-level-on-bat +Same as @code{radeon-dpm-perf-ac} but on BAT mode. + +Defaults to @samp{"auto"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-ac? +Wifi power saving mode. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} on-off-boolean wifi-pwr-on-bat? +Same as @code{wifi-power-ac?} but on BAT mode. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} y-n-boolean wol-disable? +Disable wake on LAN. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-ac +Timeout duration in seconds before activating audio power saving on +Intel HDA and AC97 devices. A value of 0 disables power saving. + +Defaults to @samp{0}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} non-negative-integer sound-power-save-on-bat +Same as @code{sound-powersave-ac} but on BAT mode. + +Defaults to @samp{1}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} y-n-boolean sound-power-save-controller? +Disable controller in powersaving mode on Intel HDA devices. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean bay-poweroff-on-bat? +Enable optical drive in UltraBay/MediaBay on BAT mode. Drive can be +powered on again by releasing (and reinserting) the eject lever or by +pressing the disc eject button on newer models. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string bay-device +Name of the optical drive device to power off. + +Defaults to @samp{"sr0"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-ac +Runtime Power Management for PCI(e) bus devices. Alternatives are on +and auto. + +Defaults to @samp{"on"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} string runtime-pm-on-bat +Same as @code{runtime-pm-ac} but on BAT mode. + +Defaults to @samp{"auto"}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean runtime-pm-all? +Runtime Power Management for all PCI(e) bus devices, except blacklisted +ones. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-space-separated-string-list runtime-pm-blacklist +Exclude specified PCI(e) devices adresses from Runtime Power Management. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} space-separated-string-list runtime-pm-driver-blacklist +Exclude PCI(e) devices assigned to the specified drivers from Runtime +Power Management. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean usb-autosuspend? +Enable USB autosuspend feature. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-string usb-blacklist +Exclude specified devices from USB autosuspend. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean usb-blacklist-wwan? +Exclude WWAN devices from USB autosuspend. + +Defaults to @samp{#t}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-string usb-whitelist +Include specified devices into USB autosuspend, even if they are already +excluded by the driver or via @code{usb-blacklist-wwan?}. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} maybe-boolean usb-autosuspend-disable-on-shutdown? +Enable USB autosuspend before shutdown. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{tlp-configuration} parameter} boolean restore-device-state-on-startup? +Restore radio device state (bluetooth, wifi, wwan) from previous +shutdown on system startup. + +Defaults to @samp{#f}. + +@end deftypevr + @node Miscellaneous Services @subsubsection Miscellaneous Services diff --git a/gnu/local.mk b/gnu/local.mk index 0eb18f26c1..f589cd9468 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -10,6 +10,7 @@ # Copyright © 2016, 2017 Ricardo Wurmus # Copyright © 2016 Ben Woodcroft # Copyright © 2017 Clément Lassieur +# Copyright © 2017 Mathieu Othacehe # # This file is part of GNU Guix. # @@ -422,6 +423,7 @@ GNU_SYSTEM_MODULES = \ %D%/services/nfs.scm \ %D%/services/shepherd.scm \ %D%/services/herd.scm \ + %D%/services/pm.scm \ %D%/services/sddm.scm \ %D%/services/spice.scm \ %D%/services/ssh.scm \ diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm new file mode 100644 index 0000000000..ec35e5701a --- /dev/null +++ b/gnu/services/pm.scm @@ -0,0 +1,404 @@ +;;; 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 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)) + +(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.") + + (energy-perf-policy-on-bat + (string "powersave") + "Same as @code{energy-perf-policy-ac} but on BAT mode.") + + (disks-devices + (space-separated-string-list '("sda")) + "Hard disk devices.") + + (disk-apm-level-on-ac + (space-separated-string-list '("254" "254")) + "Hard disk advanced power management level.") + + (disk-apm-level-on-bat + (space-separated-string-list '("128" "128")) + "Same as @code{disk-apm-bat} but on BAT mode.") + + (disk-spindown-timeout-on-ac + (maybe-space-separated-string-list 'disabled) + "Hard disk spin down timeout. One value has to be specified for +each declared hard disk.") + + (disk-spindown-timeout-on-bat + (maybe-space-separated-string-list 'disabled) + "Same as @code{disk-spindown-timeout-on-ac} but on BAT mode.") + + (disk-iosched + (maybe-space-separated-string-list 'disabled) + "Select IO scheduler for disk devices. One value has to be specified +for each declared hard disk. Example alternatives are cfq, deadline and noop.") + + (sata-linkpwr-on-ac + (string "max_performance") + "SATA aggressive link power management (ALPM) level. Alternatives are +min_power, medium_power, max_performance.") + + (sata-linkpwr-on-bat + (string "min_power") + "Same as @code{sata-linkpwr-ac} but on BAT mode.") + + (sata-linkpwr-blacklist + (maybe-string 'disabled) + "Exclude specified SATA host devices for link power management.") + + (ahci-runtime-pm-on-ac? + (maybe-on-off-boolean 'disabled) + "Enable Runtime Power Management for AHCI controller and disks +on AC mode.") + + (ahci-runtime-pm-on-bat? + (maybe-on-off-boolean 'disabled) + "Same as @code{ahci-runtime-pm-on-ac} on BAT mode.") + + (ahci-runtime-pm-timeout + (non-negative-integer 15) + "Seconds of inactivity before disk is suspended.") + + (pcie-aspm-on-ac + (string "performance") + "PCI Express Active State Power Management level. Alternatives are +default, performance, powersave.") + + (pcie-aspm-on-bat + (string "powersave") + "Same as @code{pcie-aspm-ac} but on BAT mode.") + + (radeon-power-profile-on-ac + (string "high") + "Radeon graphics clock speed level. Alternatives are +low, mid, high, auto, default.") + + (radeon-power-profile-on-bat + (string "low") + "Same as @code{radeon-power-ac} but on BAT mode.") + + (radeon-dpm-state-on-ac + (string "performance") + "Radeon dynamic power management method (DPM). Alternatives are +battery, performance.") + + (radeon-dpm-state-on-bat + (string "battery") + "Same as @code{radeon-dpm-state-ac} but on BAT mode.") + + (radeon-dpm-perf-level-on-ac + (string "auto") + "Radeon DPM performance level. Alternatives are +auto, low, high.") + + (radeon-dpm-perf-level-on-bat + (string "auto") + "Same as @code{radeon-dpm-perf-ac} but on BAT mode.") + + (wifi-pwr-on-ac? + (on-off-boolean #f) + "Wifi power saving mode.") + + (wifi-pwr-on-bat? + (on-off-boolean #t) + "Same as @code{wifi-power-ac?} but on BAT mode.") + + (wol-disable? + (y-n-boolean #t) + "Disable wake on LAN.") + + (sound-power-save-on-ac + (non-negative-integer 0) + "Timeout duration in seconds before activating audio power saving + on Intel HDA and AC97 devices. A value of 0 disables power saving.") + + (sound-power-save-on-bat + (non-negative-integer 1) + "Same as @code{sound-powersave-ac} but on BAT mode.") + + (sound-power-save-controller? + (y-n-boolean #t) + "Disable controller in powersaving mode on Intel HDA devices.") + + (bay-poweroff-on-bat? + (boolean #f) + "Enable optical drive in UltraBay/MediaBay on BAT mode. +Drive can be powered on again by releasing (and reinserting) the eject lever +or by pressing the disc eject button on newer models.") + + (bay-device + (string "sr0") + "Name of the optical drive device to power off.") + + (runtime-pm-on-ac + (string "on") + "Runtime Power Management for PCI(e) bus devices. Alternatives are +on and auto.") + + (runtime-pm-on-bat + (string "auto") + "Same as @code{runtime-pm-ac} but on BAT mode.") + + (runtime-pm-all? + (boolean #t) + "Runtime Power Management for all PCI(e) bus devices, except +blacklisted ones.") + + (runtime-pm-blacklist + (maybe-space-separated-string-list 'disabled) + "Exclude specified PCI(e) devices adresses from Runtime Power Management.") + + (runtime-pm-driver-blacklist + (space-separated-string-list '("radeon" "nouveau")) + "Exclude PCI(e) devices assigned to the specified drivers from +Runtime Power Management.") + + (usb-autosuspend? + (boolean #t) + "Enable USB autosuspend feature.") + + (usb-blacklist + (maybe-string 'disabled) + "Exclude specified devices from USB autosuspend.") + + (usb-blacklist-wwan? + (boolean #t) + "Exclude WWAN devices from USB autosuspend.") + + (usb-whitelist + (maybe-string 'disabled) + "Include specified devices into USB autosuspend, even if they are +already excluded by the driver or via @code{usb-blacklist-wwan?}.") + + (usb-autosuspend-disable-on-shutdown? + (maybe-boolean 'disabled) + "Enable USB autosuspend before shutdown.") + + (restore-device-state-on-startup? + (boolean #f) + "Restore radio device state (bluetooth, wifi, wwan) from previous +shutdown on system startup.")) + + +(define (tlp-shepherd-service config) + (let* ((tlp-bin (file-append + (tlp-configuration-tlp config) "/bin/tlp")) + (tlp-action (lambda args + #~(lambda _ + (zero? (system* #$tlp-bin #$@args)))))) + (list (shepherd-service + (documentation "Run TLP script.") + (provision '(tlp)) + (requirement '(user-processes)) + (start (tlp-action "init" "start")) + (stop (tlp-action "init" "stop")))))) + +(define (tlp-activation config) + (let* ((config-str (with-output-to-string + (lambda () + (serialize-configuration + config + tlp-configuration-fields)))) + (config-file (plain-file "tlp" config-str))) + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (copy-file #$config-file "/etc/tlp"))))) + +(define tlp-service-type + (service-type + (name 'tlp) + (extensions + (list + (service-extension shepherd-root-service-type + tlp-shepherd-service) + (service-extension udev-service-type + (compose list tlp-configuration-tlp)) + (service-extension activation-service-type + tlp-activation))))) + +(define (generate-tlp-documentation) + (generate-documentation + `((tlp-configuration ,tlp-configuration-fields)) + 'tlp-configuration)) -- cgit v1.2.3 From 1c17a863f6816a086595106ac553c67e3f177954 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Fri, 24 Mar 2017 11:00:17 +0100 Subject: doc: Re-generate openvpn service documentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/guix.texi (VPN Services): Generate documentation with generate-openvpn-server-documentation and generate-openvpn-client-documentation helpers and guile 2.1.7. Signed-off-by: Clément Lassieur --- doc/guix.texi | 88 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index 5649b089c2..6aa279edc3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13113,19 +13113,19 @@ Both can be run simultaneously. Available @code{openvpn-client-configuration} fields are: -@deftypevr @code{openvpn-client-configuration} parameter package openvpn +@deftypevr {@code{openvpn-client-configuration} parameter} package openvpn The OpenVPN package. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter string pid-file +@deftypevr {@code{openvpn-client-configuration} parameter} string pid-file The OpenVPN pid file. Defaults to @samp{"/var/run/openvpn/openvpn.pid"}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter proto proto +@deftypevr {@code{openvpn-client-configuration} parameter} proto proto The protocol (UDP or TCP) used to open a channel between clients and servers. @@ -13133,21 +13133,21 @@ Defaults to @samp{udp}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter dev dev +@deftypevr {@code{openvpn-client-configuration} parameter} dev dev The device type used to represent the VPN connection. Defaults to @samp{tun}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter string ca +@deftypevr {@code{openvpn-client-configuration} parameter} string ca The certificate authority to check connections against. Defaults to @samp{"/etc/openvpn/ca.crt"}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter string cert +@deftypevr {@code{openvpn-client-configuration} parameter} string cert The certificate of the machine the daemon is running on. It should be signed by the authority given in @code{ca}. @@ -13155,7 +13155,7 @@ Defaults to @samp{"/etc/openvpn/client.crt"}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter string key +@deftypevr {@code{openvpn-client-configuration} parameter} string key The key of the machine the daemon is running on. It must be the key whose certificate is @code{cert}. @@ -13163,21 +13163,21 @@ Defaults to @samp{"/etc/openvpn/client.key"}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter boolean comp-lzo? +@deftypevr {@code{openvpn-client-configuration} parameter} boolean comp-lzo? Whether to use the lzo compression algorithm. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter boolean persist-key? +@deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-key? Don't re-read key files across SIGUSR1 or --ping-restart. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter boolean persist-tun? +@deftypevr {@code{openvpn-client-configuration} parameter} boolean persist-tun? Don't close and reopen TUN/TAP device or run up/down scripts across SIGUSR1 or --ping-restart restarts. @@ -13185,14 +13185,14 @@ Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter number verbosity +@deftypevr {@code{openvpn-client-configuration} parameter} number verbosity Verbosity level. Defaults to @samp{3}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter tls-auth-client tls-auth +@deftypevr {@code{openvpn-client-configuration} parameter} tls-auth-client tls-auth Add an additional layer of HMAC authentication on top of the TLS control channel to protect against DoS attacks. @@ -13200,42 +13200,42 @@ Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter key-usage verify-key-usage? +@deftypevr {@code{openvpn-client-configuration} parameter} key-usage verify-key-usage? Whether to check the server certificate has server usage extension. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter bind bind? +@deftypevr {@code{openvpn-client-configuration} parameter} bind bind? Bind to a specific local port number. Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter resolv-retry resolv-retry? +@deftypevr {@code{openvpn-client-configuration} parameter} resolv-retry resolv-retry? Retry resolving server address. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-client-configuration} parameter openvpn-remote-list remote +@deftypevr {@code{openvpn-client-configuration} parameter} openvpn-remote-list remote A list of remote servers to connect to. Defaults to @samp{()}. Available @code{openvpn-remote-configuration} fields are: -@deftypevr @code{openvpn-remote-configuration} parameter string name +@deftypevr {@code{openvpn-remote-configuration} parameter} string name Server name. Defaults to @samp{"my-server"}. @end deftypevr -@deftypevr @code{openvpn-remote-configuration} parameter number port +@deftypevr {@code{openvpn-remote-configuration} parameter} number port Port number the server listens to. Defaults to @samp{1194}. @@ -13249,19 +13249,19 @@ Defaults to @samp{1194}. Available @code{openvpn-server-configuration} fields are: -@deftypevr @code{openvpn-server-configuration} parameter package openvpn +@deftypevr {@code{openvpn-server-configuration} parameter} package openvpn The OpenVPN package. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string pid-file +@deftypevr {@code{openvpn-server-configuration} parameter} string pid-file The OpenVPN pid file. Defaults to @samp{"/var/run/openvpn/openvpn.pid"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter proto proto +@deftypevr {@code{openvpn-server-configuration} parameter} proto proto The protocol (UDP or TCP) used to open a channel between clients and servers. @@ -13269,21 +13269,21 @@ Defaults to @samp{udp}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter dev dev +@deftypevr {@code{openvpn-server-configuration} parameter} dev dev The device type used to represent the VPN connection. Defaults to @samp{tun}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string ca +@deftypevr {@code{openvpn-server-configuration} parameter} string ca The certificate authority to check connections against. Defaults to @samp{"/etc/openvpn/ca.crt"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string cert +@deftypevr {@code{openvpn-server-configuration} parameter} string cert The certificate of the machine the daemon is running on. It should be signed by the authority given in @code{ca}. @@ -13291,7 +13291,7 @@ Defaults to @samp{"/etc/openvpn/client.crt"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string key +@deftypevr {@code{openvpn-server-configuration} parameter} string key The key of the machine the daemon is running on. It must be the key whose certificate is @code{cert}. @@ -13299,21 +13299,21 @@ Defaults to @samp{"/etc/openvpn/client.key"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter boolean comp-lzo? +@deftypevr {@code{openvpn-server-configuration} parameter} boolean comp-lzo? Whether to use the lzo compression algorithm. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter boolean persist-key? +@deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-key? Don't re-read key files across SIGUSR1 or --ping-restart. Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter boolean persist-tun? +@deftypevr {@code{openvpn-server-configuration} parameter} boolean persist-tun? Don't close and reopen TUN/TAP device or run up/down scripts across SIGUSR1 or --ping-restart restarts. @@ -13321,14 +13321,14 @@ Defaults to @samp{#t}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter number verbosity +@deftypevr {@code{openvpn-server-configuration} parameter} number verbosity Verbosity level. Defaults to @samp{3}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter tls-auth-server tls-auth +@deftypevr {@code{openvpn-server-configuration} parameter} tls-auth-server tls-auth Add an additional layer of HMAC authentication on top of the TLS control channel to protect against DoS attacks. @@ -13336,56 +13336,56 @@ Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter number port +@deftypevr {@code{openvpn-server-configuration} parameter} number port Specifies the port number on which the server listens. Defaults to @samp{1194}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter ip-mask server +@deftypevr {@code{openvpn-server-configuration} parameter} ip-mask server An ip and mask specifying the subnet inside the virtual network. Defaults to @samp{"10.8.0.0 255.255.255.0"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter cidr6 server-ipv6 +@deftypevr {@code{openvpn-server-configuration} parameter} cidr6 server-ipv6 A CIDR notation specifying the IPv6 subnet inside the virtual network. Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string dh +@deftypevr {@code{openvpn-server-configuration} parameter} string dh The Diffie-Hellman parameters file. Defaults to @samp{"/etc/openvpn/dh2048.pem"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string ifconfig-pool-persist +@deftypevr {@code{openvpn-server-configuration} parameter} string ifconfig-pool-persist The file that records client IPs. Defaults to @samp{"/etc/openvpn/ipp.txt"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter gateway redirect-gateway? +@deftypevr {@code{openvpn-server-configuration} parameter} gateway redirect-gateway? When true, the server will act as a gateway for its clients. Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter boolean client-to-client? +@deftypevr {@code{openvpn-server-configuration} parameter} boolean client-to-client? When true, clients are alowed to talk to each other inside the VPN. Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter keepalive keepalive +@deftypevr {@code{openvpn-server-configuration} parameter} keepalive keepalive Causes ping-like messages to be sent back and forth over the link so that each side knows when the other side has gone down. @code{keepalive} requires a pair. The first element is the period of the ping sending, @@ -13394,14 +13394,14 @@ down. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter number max-clients +@deftypevr {@code{openvpn-server-configuration} parameter} number max-clients The maximum number of clients. Defaults to @samp{100}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter string status +@deftypevr {@code{openvpn-server-configuration} parameter} string status The status file. This file shows a small report on current connection. It is trunkated and rewritten every minute. @@ -13409,28 +13409,28 @@ Defaults to @samp{"/var/run/openvpn/status"}. @end deftypevr -@deftypevr @code{openvpn-server-configuration} parameter openvpn-ccd-list client-config-dir +@deftypevr {@code{openvpn-server-configuration} parameter} openvpn-ccd-list client-config-dir The list of configuration for some clients. Defaults to @samp{()}. Available @code{openvpn-ccd-configuration} fields are: -@deftypevr @code{openvpn-ccd-configuration} parameter string name +@deftypevr {@code{openvpn-ccd-configuration} parameter} string name Client name. Defaults to @samp{"client"}. @end deftypevr -@deftypevr @code{openvpn-ccd-configuration} parameter ip-mask iroute +@deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask iroute Client own network Defaults to @samp{#f}. @end deftypevr -@deftypevr @code{openvpn-ccd-configuration} parameter ip-mask ifconfig-push +@deftypevr {@code{openvpn-ccd-configuration} parameter} ip-mask ifconfig-push Client VPN IP. Defaults to @samp{#f}. -- cgit v1.2.3 From 9260b9d1005559f526569bcf694e9c9b40d85800 Mon Sep 17 00:00:00 2001 From: Thomas Danckaert Date: Tue, 14 Mar 2017 18:12:34 +0100 Subject: services: Add inetd-service-type. * gnu/services/networking.scm (, ): New record types. (inetd-config-file, inetd-shepherd-service): New procedures. (inetd-service-type): New variable. * doc/guix.texi (Networking Services): Document it. * gnu/tests/networking.scm: New file. * gnu/local.mk: Add it. --- doc/guix.texi | 96 +++++++++++++++++++++++++++- gnu/local.mk | 1 + gnu/services/networking.scm | 89 ++++++++++++++++++++++++++ gnu/tests/networking.scm | 149 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 gnu/tests/networking.scm (limited to 'doc/guix.texi') diff --git a/doc/guix.texi b/doc/guix.texi index 6aa279edc3..57595b95e7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -33,7 +33,8 @@ Copyright @copyright{} 2016 Alex ter Weele@* Copyright @copyright{} 2017 Clément Lassieur@* Copyright @copyright{} 2017 Mathieu Othacehe@* Copyright @copyright{} 2017 Federico Beffa@* -Copyright @copyright{} 2017 Carlo Zancanaro +Copyright @copyright{} 2017 Carlo Zancanaro@* +Copyright @copyright{} 2017 Thomas Danckaert Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -9400,6 +9401,99 @@ make an initial adjustment of more than 1,000 seconds. List of host names used as the default NTP servers. @end defvr +@cindex inetd +@deffn {Scheme variable} inetd-service-type +This service runs the @command{inetd} (@pxref{inetd invocation,,, +inetutils, GNU Inetutils}) daemon. @command{inetd} listens for +connections on internet sockets, and lazily starts the specified server +program when a connection is made on one of these sockets. + +The value of this service is an @code{inetd-configuration} object. The +following example configures the @command{inetd} daemon to provide the +built-in @command{echo} service, as well as an smtp service which +forwards smtp traffic over ssh to a server @code{smtp-server} behind a +gateway @code{hostname}: + +@example +(service + inetd-service-type + (inetd-configuration + (entries (list + (inetd-entry + (name "echo") + (socket-type 'stream) + (protocol "tcp") + (wait? #f) + (user "root")) + (inetd-entry + (node "127.0.0.1") + (name "smtp") + (socket-type 'stream) + (protocol "tcp") + (wait? #f) + (user "root") + (program (file-append openssh "/bin/ssh")) + (arguments + '("ssh" "-qT" "-i" "/path/to/ssh_key" + "-W" "smtp-server:25" "user@@hostname"))))) +@end example + +See below for more details about @code{inetd-configuration}. +@end deffn + +@deftp {Data Type} inetd-configuration +Data type representing the configuration of @command{inetd}. + +@table @asis +@item @code{program} (default: @code{(file-append inetutils "/libexec/inetd")}) +The @command{inetd} executable to use. + +@item @code{entries} (default: @code{'()}) +A list of @command{inetd} service entries. Each entry should be created +by the @code{inetd-entry} constructor. +@end table +@end deftp + +@deftp {Data Type} inetd-entry +Data type representing an entry in the @command{inetd} configuration. +Each entry corresponds to a socket where @command{inetd} will listen for +requests. + +@table @asis +@item @code{node} (default: @code{#f}) +Optional string, a comma-separated list of local addresses +@command{inetd} should use when listening for this service. +@xref{Configuration file,,, inetutils, GNU Inetutils} for a complete +description of all options. +@item @code{name} +A string, the name must correspond to an entry in @code{/etc/services}. +@item @code{socket-type} +One of @code{'stream}, @code{'dgram}, @code{'raw}, @code{'rdm} or +@code{'seqpacket}. +@item @code{protocol} +A string, must correspond to an entry in @code{/etc/protocols}. +@item @code{wait?} (default: @code{#t}) +Whether @command{inetd} should wait for the server to exit before +listening to new service requests. +@item @code{user} +A string containing the user (and, optionally, group) name of the user +as whom the server should run. The group name can be specified in a +suffix, separated by a colon or period, i.e. @code{"user"}, +@code{"user:group"} or @code{"user.group"}. +@item @code{program} (default: @code{"internal"}) +The server program which will serve the requests, or @code{"internal"} +if @command{inetd} should use a built-in service. +@item @code{arguments} (default: @code{'()}) +A list strings or file-like objects, which are the server program's +arguments, starting with the zeroth argument, i.e. the name of the +program itself. For @command{inetd}'s internal services, this entry +must be @code{'()} or @code{'("internal")}. +@end table + +@xref{Configuration file,,, inetutils, GNU Inetutils} for a more +detailed discussion of each configuration field. +@end deftp + @cindex Tor @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}] Return a service to run the @uref{https://torproject.org, Tor} anonymous diff --git a/gnu/local.mk b/gnu/local.mk index f589cd9468..0bb2276a2a 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -464,6 +464,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/install.scm \ %D%/tests/mail.scm \ %D%/tests/messaging.scm \ + %D%/tests/networking.scm \ %D%/tests/ssh.scm \ %D%/tests/web.scm diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 9b8e5b36b1..85fc0b843a 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2016 Efraim Flashner ;;; Copyright © 2016 John Darrington ;;; Copyright © 2017 Clément Lassieur +;;; Copyright © 2017 Thomas Danckaert ;;; ;;; This file is part of GNU Guix. ;;; @@ -61,6 +62,10 @@ ntp-service ntp-service-type + inetd-configuration + inetd-entry + inetd-service-type + tor-configuration tor-configuration? tor-hidden-service @@ -430,6 +435,90 @@ make an initial adjustment of more than 1,000 seconds." (allow-large-adjustment? allow-large-adjustment?)))) + +;;; +;;; Inetd. +;;; + +(define-record-type* inetd-configuration + make-inetd-configuration + inetd-configuration? + (program inetd-configuration-program ;file-like + (default (file-append inetutils "/libexec/inetd"))) + (entries inetd-configuration-entries ;list of + (default '()))) + +(define-record-type* inetd-entry make-inetd-entry + inetd-entry? + (node inetd-entry-node ;string or #f + (default #f)) + (name inetd-entry-name) ;string, from /etc/services + + (socket-type inetd-entry-socket-type) ;stream | dgram | raw | + ;rdm | seqpacket + (protocol inetd-entry-protocol) ;string, from /etc/protocols + + (wait? inetd-entry-wait? ;Boolean + (default #t)) + (user inetd-entry-user) ;string + + (program inetd-entry-program ;string or file-like object + (default "internal")) + (arguments inetd-entry-arguments ;list of strings or file-like objects + (default '()))) + +(define (inetd-config-file entries) + (apply mixed-text-file "inetd.conf" + (map + (lambda (entry) + (let* ((node (inetd-entry-node entry)) + (name (inetd-entry-name entry)) + (socket + (if node (string-append node ":" name) name)) + (type + (match (inetd-entry-socket-type entry) + ((or 'stream 'dgram 'raw 'rdm 'seqpacket) + (symbol->string (inetd-entry-socket-type entry))))) + (protocol (inetd-entry-protocol entry)) + (wait (if (inetd-entry-wait? entry) "wait" "nowait")) + (user (inetd-entry-user entry)) + (program (inetd-entry-program entry)) + (args (inetd-entry-arguments entry))) + #~(string-append + (string-join + (list #$@(list socket type protocol wait user program) #$@args) + " ") "\n"))) + entries))) + +(define inetd-shepherd-service + (match-lambda + (($ program ()) '()) ; empty list of entries -> do nothing + (($ program entries) + (list + (shepherd-service + (documentation "Run inetd.") + (provision '(inetd)) + (requirement '(user-processes networking syslogd)) + (start #~(make-forkexec-constructor + (list #$program #$(inetd-config-file entries)) + #:pid-file "/var/run/inetd.pid")) + (stop #~(make-kill-destructor))))))) + +(define-public inetd-service-type + (service-type + (name 'inetd) + (extensions + (list (service-extension shepherd-root-service-type + inetd-shepherd-service))) + + ;; The service can be extended with additional lists of entries. + (compose concatenate) + (extend (lambda (config entries) + (inetd-configuration + (inherit config) + (entries (append (inetd-configuration-entries config) + entries))))))) + ;;; ;;; Tor. diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm new file mode 100644 index 0000000000..53c80a4ac1 --- /dev/null +++ b/gnu/tests/networking.scm @@ -0,0 +1,149 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2017 Thomas Danckaert +;;; +;;; 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 tests networking) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system grub) + #:use-module (gnu system file-systems) + #:use-module (gnu system shadow) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services base) + #:use-module (gnu services networking) + #:use-module (guix gexp) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (gnu packages bash) + #:export (%test-inetd)) + +(define %inetd-os + ;; Operating system with 2 inetd services. + (operating-system + (host-name "komputilo") + (timezone "Europe/Brussels") + (locale "en_US.utf8") + + (bootloader (grub-configuration (device "/dev/sdX"))) + (file-systems %base-file-systems) + (firmware '()) + (users %base-user-accounts) + (services (cons* (dhcp-client-service) + (service inetd-service-type + (inetd-configuration + (entries (list + (inetd-entry + (name "echo") + (socket-type 'stream) + (protocol "tcp") + (wait? #f) + (user "root")) + (inetd-entry + (name "dict") + (socket-type 'stream) + (protocol "tcp") + (wait? #f) + (user "root") + (program (file-append bash + "/bin/bash")) + (arguments + (list "bash" (plain-file "my-dict.sh" "\ +while read line +do + if [[ $line =~ ^DEFINE\\ (.*)$ ]] + then + case ${BASH_REMATCH[1]} in + Guix) + echo GNU Guix is a package management tool for the GNU system. + ;; + G-expression) + echo Like an S-expression but with a G. + ;; + *) + echo NO DEFINITION FOUND + ;; + esac + else + echo ERROR + fi +done" )))))))) + %base-services)))) + +(define* (run-inetd-test) + "Run tests in %INETD-OS, where the inetd service provides an echo service on +port 7, and a dict service on port 2628." + (mlet* %store-monad ((os -> (marionette-operating-system %inetd-os)) + (command (system-qemu-image/shared-store-script + os #:graphic? #f))) + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (ice-9 rdelim) + (srfi srfi-64) + (gnu build marionette)) + (define marionette + ;; Forward guest ports 7 and 2628 to host ports 8007 and 8628. + (make-marionette (list #$command "-net" + (string-append + "user" + ",hostfwd=tcp::8007-:7" + ",hostfwd=tcp::8628-:2628")))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "inetd") + + ;; Make sure the PID file is created. + (test-assert "PID file" + (marionette-eval + '(file-exists? "/var/run/inetd.pid") + marionette)) + + ;; Test the echo service. + (test-equal "echo response" + "Hello, Guix!" + (let ((echo (socket PF_INET SOCK_STREAM 0)) + (addr (make-socket-address AF_INET INADDR_LOOPBACK 8007))) + (connect echo addr) + (display "Hello, Guix!\n" echo) + (let ((response (read-line echo))) + (close echo) + response))) + + ;; Test the dict service + (test-equal "dict response" + "GNU Guix is a package management tool for the GNU system." + (let ((dict (socket PF_INET SOCK_STREAM 0)) + (addr (make-socket-address AF_INET INADDR_LOOPBACK 8628))) + (connect dict addr) + (display "DEFINE Guix\n" dict) + (let ((response (read-line dict))) + (close dict) + response))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "inetd-test" test))) + +(define %test-inetd + (system-test + (name "inetd") + (description "Connect to a host with an INETD server.") + (value (run-inetd-test)))) -- cgit v1.2.3