You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.7 KiB

  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. (define-module (gnu services sysctl)
  19. #:use-module (gnu services)
  20. #:use-module (gnu services shepherd)
  21. #:use-module (gnu packages linux)
  22. #:use-module (guix gexp)
  23. #:use-module (guix records)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (ice-9 match)
  26. #:export (sysctl-configuration
  27. sysctl-service-type))
  28. ;;;
  29. ;;; System Control Service.
  30. ;;;
  31. (define-record-type* <sysctl-configuration>
  32. sysctl-configuration make-sysctl-configuration
  33. sysctl-configuration?
  34. (sysctl sysctl-configuration-sysctl ; path of the 'sysctl' command
  35. (default (file-append procps "/sbin/sysctl")))
  36. (settings sysctl-configuration-settings ; alist of string pairs
  37. (default '())))
  38. (define (sysctl-configuration-settings->sysctl.conf settings)
  39. "Return a file for @command{sysctl} to set kernel parameters as specified by
  40. @var{settings}."
  41. (apply mixed-text-file "sysctl.conf"
  42. (append-map (match-lambda
  43. ((key . value)
  44. (list key "=" value "\n")))
  45. settings)))
  46. (define sysctl-shepherd-service
  47. (match-lambda
  48. (($ <sysctl-configuration> sysctl settings)
  49. (let ((sysctl.conf
  50. (sysctl-configuration-settings->sysctl.conf settings)))
  51. (shepherd-service
  52. (documentation "Configure kernel parameters at boot.")
  53. (provision '(sysctl))
  54. (start #~(lambda _
  55. (zero? (system* #$sysctl "--load" #$sysctl.conf))))
  56. (one-shot? #t))))))
  57. (define sysctl-service-type
  58. (service-type
  59. (name 'sysctl)
  60. (extensions
  61. (list (service-extension shepherd-root-service-type
  62. (compose list sysctl-shepherd-service))))
  63. (compose concatenate)
  64. (extend (lambda (config settings)
  65. (sysctl-configuration
  66. (inherit config)
  67. (settings (append (sysctl-configuration-settings config)
  68. settings)))))
  69. (default-value (sysctl-configuration))))