| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 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-configuration-sysctl
|
| 29 | sysctl-configuration-settings
|
| 30 | sysctl-service-type
|
| 31 | %default-sysctl-settings))
|
| 32 |
|
| 33 |
|
| 34 | |
| 35 | |
| 36 | |
| 37 |
|
| 38 | (define %default-sysctl-settings
|
| 39 | |
| 40 | '(("fs.protected_hardlinks" . "1")
|
| 41 | ("fs.protected_symlinks" . "1")))
|
| 42 |
|
| 43 | (define-record-type* <sysctl-configuration>
|
| 44 | sysctl-configuration make-sysctl-configuration
|
| 45 | sysctl-configuration?
|
| 46 | (sysctl sysctl-configuration-sysctl |
| 47 | (default (file-append procps "/sbin/sysctl")))
|
| 48 | (settings sysctl-configuration-settings |
| 49 | (default %default-sysctl-settings)))
|
| 50 |
|
| 51 | (define (sysctl-configuration-settings->sysctl.conf settings)
|
| 52 | "Return a file for @command{sysctl} to set kernel parameters as specified by
|
| 53 | @var{settings}."
|
| 54 | (apply mixed-text-file "sysctl.conf"
|
| 55 | (append-map (match-lambda
|
| 56 | ((key . value)
|
| 57 | (list key "=" value "\n")))
|
| 58 | settings)))
|
| 59 |
|
| 60 | (define sysctl-shepherd-service
|
| 61 | (match-lambda
|
| 62 | (($ <sysctl-configuration> sysctl settings)
|
| 63 | (let ((sysctl.conf
|
| 64 | (sysctl-configuration-settings->sysctl.conf settings)))
|
| 65 | (shepherd-service
|
| 66 | (documentation "Configure kernel parameters at boot.")
|
| 67 | (provision '(sysctl))
|
| 68 | (start #~(lambda _
|
| 69 | (zero? (system* #$sysctl "--load" #$sysctl.conf))))
|
| 70 | (one-shot? #t))))))
|
| 71 |
|
| 72 | (define sysctl-service-type
|
| 73 | (service-type
|
| 74 | (name 'sysctl)
|
| 75 | (extensions
|
| 76 | (list (service-extension shepherd-root-service-type
|
| 77 | (compose list sysctl-shepherd-service))))
|
| 78 | (compose concatenate)
|
| 79 | (extend (lambda (config settings)
|
| 80 | (sysctl-configuration
|
| 81 | (inherit config)
|
| 82 | (settings (append (sysctl-configuration-settings config)
|
| 83 | settings)))))
|
| 84 | (default-value (sysctl-configuration))
|
| 85 | (description "Set Linux kernel parameters under @file{/proc/sys} at system
|
| 86 | startup time.")))
|