services: science.scm: Add missing copyright headers.
[jackhill/guix/guix.git] / gnu / services / sysctl.scm
CommitLineData
296bf4d5
SB
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Sou Bunnbu <iyzsong@member.fsf.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu services sysctl)
20 #:use-module (gnu services)
21 #:use-module (gnu services shepherd)
22 #:use-module (gnu packages linux)
23 #:use-module (guix gexp)
24 #:use-module (guix records)
25 #:use-module (srfi srfi-1)
26 #:use-module (ice-9 match)
27 #:export (sysctl-configuration
28 sysctl-service-type))
29
30\f
31;;;
32;;; System Control Service.
33;;;
34
35(define-record-type* <sysctl-configuration>
172b3e2c 36 sysctl-configuration make-sysctl-configuration
296bf4d5
SB
37 sysctl-configuration?
38 (sysctl sysctl-configuration-sysctl ; path of the 'sysctl' command
39 (default (file-append procps "/sbin/sysctl")))
40 (settings sysctl-configuration-settings ; alist of string pairs
41 (default '())))
42
43(define (sysctl-configuration-settings->sysctl.conf settings)
44 "Return a file for @command{sysctl} to set kernel parameters as specified by
45@var{settings}."
46 (apply mixed-text-file "sysctl.conf"
47 (append-map (match-lambda
48 ((key . value)
49 (list key "=" value "\n")))
50 settings)))
51
52(define sysctl-shepherd-service
53 (match-lambda
54 (($ <sysctl-configuration> sysctl settings)
55 (let ((sysctl.conf
56 (sysctl-configuration-settings->sysctl.conf settings)))
57 (shepherd-service
58 (documentation "Configure kernel parameters at boot.")
59 (provision '(sysctl))
60 (start #~(lambda _
61 (zero? (system* #$sysctl "--load" #$sysctl.conf))))
77ed06a8 62 (one-shot? #t))))))
296bf4d5
SB
63
64(define sysctl-service-type
65 (service-type
66 (name 'sysctl)
67 (extensions
68 (list (service-extension shepherd-root-service-type
69 (compose list sysctl-shepherd-service))))
70 (compose concatenate)
71 (extend (lambda (config settings)
72 (sysctl-configuration
73 (inherit config)
74 (settings (append (sysctl-configuration-settings config)
75 settings)))))
76 (default-value (sysctl-configuration))))