1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Sou Bunnbu <iyzsong@member.fsf.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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
32 ;;; System Control Service.
35 (define-record-type* <sysctl-configuration>
36 sysctl-configuration make-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
43 (define (sysctl-configuration-settings->sysctl.conf settings)
44 "Return a file for @command{sysctl} to set kernel parameters as specified by
46 (apply mixed-text-file "sysctl.conf"
47 (append-map (match-lambda
49 (list key "=" value "\n")))
52 (define sysctl-shepherd-service
54 (($ <sysctl-configuration> sysctl settings)
56 (sysctl-configuration-settings->sysctl.conf settings)))
58 (documentation "Configure kernel parameters at boot.")
61 (zero? (system* #$sysctl "--load" #$sysctl.conf))))
64 (define sysctl-service-type
68 (list (service-extension shepherd-root-service-type
69 (compose list sysctl-shepherd-service))))
71 (extend (lambda (config settings)
74 (settings (append (sysctl-configuration-settings config)
76 (default-value (sysctl-configuration))))