aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Sou Bunnbu <iyzsong@member.fsf.org>
;;;
;;; 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 <http://www.gnu.org/licenses/>.

(define-module (gnu services sysctl)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu packages linux)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:export (sysctl-configuration
            sysctl-configuration-sysctl
            sysctl-configuration-settings
            sysctl-service-type
            %default-sysctl-settings))


;;;
;;; System Control Service.
;;;

(define %default-sysctl-settings
  ;; Default kernel parameters enabled with sysctl.
  '(("fs.protected_hardlinks" . "1")
    ("fs.protected_symlinks" . "1")))

(define-record-type* <sysctl-configuration>
  sysctl-configuration make-sysctl-configuration
  sysctl-configuration?
  (sysctl   sysctl-configuration-sysctl    ; path of the 'sysctl' command
            (default (file-append procps "/sbin/sysctl")))
  (settings sysctl-configuration-settings  ; alist of string pairs
            (default %default-sysctl-settings)))

(define (sysctl-configuration-settings->sysctl.conf settings)
  "Return a file for @command{sysctl} to set kernel parameters as specified by
@var{settings}."
  (apply mixed-text-file "sysctl.conf"
         (append-map (match-lambda
                       ((key . value)
                        (list key "=" value "\n")))
                     settings)))

(define sysctl-shepherd-service
  (match-lambda
    (($ <sysctl-configuration> sysctl settings)
     (let ((sysctl.conf
            (sysctl-configuration-settings->sysctl.conf settings)))
       (shepherd-service
        (documentation "Configure kernel parameters at boot.")
        (provision '(sysctl))
        (start #~(lambda _
                   (zero? (system* #$sysctl "--load" #$sysctl.conf))))
        (one-shot? #t))))))

(define sysctl-service-type
  (service-type
   (name 'sysctl)
   (extensions
    (list (service-extension shepherd-root-service-type
                             (compose list sysctl-shepherd-service))))
   (compose concatenate)
   (extend (lambda (config settings)
             (sysctl-configuration
              (inherit config)
              (settings (append (sysctl-configuration-settings config)
                                settings)))))
   (default-value (sysctl-configuration))
   (description "Set Linux kernel parameters under @file{/proc/sys} at system
startup time.")))
ommit/configure.ac?id=03cea32031bf9d641022f199f16e2eb898ff9bd3'>build: Bump version number....Ludovic Courtès 2015-12-09build: Always check for gzip/bzip2/xz....Ludovic Courtès 2015-10-20build: Set DOT_USER_PROGRAM for Emacs interface....Alex Kost 2015-10-09build: Fix libgcrypt detection on FHS systems....Ludovic Courtès 2015-10-06build: Automatically determine libgcrypt's file name....Ludovic Courtès 2015-09-25build: Bump version number....Ludovic Courtès 2015-08-30build: Produce 'guix-config' instead of using compile-time tricks....Mathieu Lirzin 2015-08-27build: Do not build (guix build syscalls) if 'mount' is missing from libc....Ludovic Courtès 2015-06-14doc: Move most 'HACKING' informations into the manual....Mathieu Lirzin 2015-06-03build: Bump version number....Ludovic Courtès 2015-06-01build: Build and install manual pages....Ludovic Courtès 2015-05-10build: Require Guile >= 2.0.7....Ludovic Courtès 2015-04-14build: Silence warnings about 'make' portability....Ludovic Courtès 2015-04-09Add Bash completion file....Ludovic Courtès 2015-04-08build: Enable silent rules by default....Ludovic Courtès 2015-03-19build: Detect lack of guile.m4 at autoconf time....Ludovic Courtès 2015-02-26build: Bump version number....Ludovic Courtès 2015-02-24build: Reject or warn against file name length limit overruns....Ludovic Courtès 2015-01-23build: Change version to 0.8.1....Ludovic Courtès 2014-12-02emacs: Move profiles code to "guix-profiles.el.in"....Alex Kost 2014-11-25build: Bump version number....Ludovic Courtès 2014-09-29import: Add PyPI importer....David Thompson 2014-09-27build: Don't generate Emacs autoloads when Emacs is unavailable....Ludovic Courtès 2014-09-03Add Emacs user interface....Alex Kost 2014-07-25build: Bump to version 0.8....Ludovic Courtès 2014-07-22Require only lower gettext version....Andreas Enge 2014-06-13Separate package description translations from string translations....Ludovic Courtès 2014-06-13Move gettext files to 'po/guix'....Ludovic Courtès 2014-05-22build: Fix builds without --with-libgcrypt-prefix nor --with-libgcrypt-libdir....Ludovic Courtès 2014-05-17build: Add --with-libgcrypt-libdir=DIR to support Debian's multi-arch layout....Ludovic Courtès 2014-04-09build: Bump to version 0.7....Ludovic Courtès 2014-03-09Change the default store file name to /gnu/store....Ludovic Courtès 2014-01-24store: Add 'register-path' procedure....Ludovic Courtès 2013-12-29build: Improve documentation of Nix-related options....Ludovic Courtès 2013-12-29config: Export '%config-directory'....Ludovic Courtès 2013-12-11build: Bump to version 0.6....Ludovic Courtès 2013-11-23build: Make sure pkg.m4 is present....Ludovic Courtès 2013-09-27build: Bump version to 0.5....Ludovic Courtès