diff options
| author | Bruno Victal <mirai@makinata.eu> | 2023-03-22 11:47:19 +0000 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-03-22 10:09:03 -0400 |
| commit | 72ef1bef07c00cda9b26af70e1fbb3c28b0824ad (patch) | |
| tree | 45878e2a7be2c1e413509a52d388b4d199cd282d /gnu/services/linux.scm | |
| parent | 2b66b54baea5feebdc45b17b7ca67710c5667936 (diff) | |
services: Add fstrim-service-type.
* gnu/services/linux.scm (fstrim-service-type): New variable.
(fstrim-mcron-job, serialize-fstrim-configuration)
(fstrim-serialize-list-of-strings, fstrim-serialize-boolean): New procedure.
(mcron-time?): New predicate.
(fstrim-configuration): New record.
* doc/guix.texi (Linux Services): Document new fstrim-service-type.
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Diffstat (limited to 'gnu/services/linux.scm')
| -rw-r--r-- | gnu/services/linux.scm | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm index 60e2093e1df..d085b375a26 100644 --- a/gnu/services/linux.scm +++ b/gnu/services/linux.scm | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> | 5 | ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com> |
| 6 | ;;; Copyright © 2021 B. Wilson <elaexuotee@wilsonb.com> | 6 | ;;; Copyright © 2021 B. Wilson <elaexuotee@wilsonb.com> |
| 7 | ;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz> | 7 | ;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz> |
| 8 | ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu> | ||
| 8 | ;;; | 9 | ;;; |
| 9 | ;;; This file is part of GNU Guix. | 10 | ;;; This file is part of GNU Guix. |
| 10 | ;;; | 11 | ;;; |
| @@ -30,12 +31,15 @@ | |||
| 30 | #:use-module (guix ui) | 31 | #:use-module (guix ui) |
| 31 | #:use-module (gnu services) | 32 | #:use-module (gnu services) |
| 32 | #:use-module (gnu services base) | 33 | #:use-module (gnu services base) |
| 34 | #:use-module (gnu services configuration) | ||
| 35 | #:use-module (gnu services mcron) | ||
| 33 | #:use-module (gnu services shepherd) | 36 | #:use-module (gnu services shepherd) |
| 34 | #:use-module (gnu packages linux) | 37 | #:use-module (gnu packages linux) |
| 35 | #:use-module (srfi srfi-1) | 38 | #:use-module (srfi srfi-1) |
| 36 | #:use-module (srfi srfi-26) | 39 | #:use-module (srfi srfi-26) |
| 37 | #:use-module (srfi srfi-34) | 40 | #:use-module (srfi srfi-34) |
| 38 | #:use-module (srfi srfi-35) | 41 | #:use-module (srfi srfi-35) |
| 42 | #:use-module (ice-9 format) | ||
| 39 | #:use-module (ice-9 match) | 43 | #:use-module (ice-9 match) |
| 40 | #:export (earlyoom-configuration | 44 | #:export (earlyoom-configuration |
| 41 | earlyoom-configuration? | 45 | earlyoom-configuration? |
| @@ -50,6 +54,16 @@ | |||
| 50 | earlyoom-configuration-send-notification-command | 54 | earlyoom-configuration-send-notification-command |
| 51 | earlyoom-service-type | 55 | earlyoom-service-type |
| 52 | 56 | ||
| 57 | fstrim-configuration | ||
| 58 | fstrim-configuration? | ||
| 59 | fstrim-configuration-package | ||
| 60 | fstrim-configuration-schedule | ||
| 61 | fstrim-configuration-listed-in | ||
| 62 | fstrim-configuration-verbose? | ||
| 63 | fstrim-configuration-quiet-unsupported? | ||
| 64 | fstrim-configuration-extra-arguments | ||
| 65 | fstrim-service-type | ||
| 66 | |||
| 53 | kernel-module-loader-service-type | 67 | kernel-module-loader-service-type |
| 54 | 68 | ||
| 55 | rasdaemon-configuration | 69 | rasdaemon-configuration |
| @@ -152,6 +166,92 @@ representation." | |||
| 152 | 166 | ||
| 153 | 167 | ||
| 154 | ;;; | 168 | ;;; |
| 169 | ;;; fstrim | ||
| 170 | ;;; | ||
| 171 | |||
| 172 | (define (mcron-time? x) | ||
| 173 | (or (procedure? x) (string? x) (list? x))) | ||
| 174 | |||
| 175 | (define-maybe list-of-strings (prefix fstrim-)) | ||
| 176 | |||
| 177 | (define (fstrim-serialize-boolean field-name value) | ||
| 178 | (list (format #f "~:[~;--~a~]" value | ||
| 179 | ;; Drop trailing '?' character. | ||
| 180 | (string-drop-right (symbol->string field-name) 1)))) | ||
| 181 | |||
| 182 | (define (fstrim-serialize-list-of-strings field-name value) | ||
| 183 | (list (string-append "--" (symbol->string field-name)) | ||
| 184 | #~(string-join '#$value ":"))) | ||
| 185 | |||
| 186 | (define-configuration fstrim-configuration | ||
| 187 | (package | ||
| 188 | (file-like util-linux) | ||
| 189 | "The package providing the @command{fstrim} command." | ||
| 190 | empty-serializer) | ||
| 191 | (schedule | ||
| 192 | (mcron-time "0 0 * * 0") | ||
| 193 | "Schedule for launching @command{fstrim}. This can be a procedure, a list | ||
| 194 | or a string. For additional information, see @ref{Guile Syntax,, | ||
| 195 | Job specification, mcron, the mcron manual}. By default this is set to run | ||
| 196 | weekly on Sunday at 00:00." | ||
| 197 | empty-serializer) | ||
| 198 | ;; The following are fstrim-related options. | ||
| 199 | (listed-in | ||
| 200 | (maybe-list-of-strings '("/etc/fstab" "/proc/self/mountinfo")) | ||
| 201 | ;; Note: documentation sourced from the fstrim manpage. | ||
| 202 | "List of files in fstab or kernel mountinfo format. All missing or | ||
| 203 | empty files are silently ignored. The evaluation of the list @emph{stops} | ||
| 204 | after the first non-empty file. File systems with @code{X-fstrim.notrim} mount | ||
| 205 | option in fstab are skipped.") | ||
| 206 | (verbose? | ||
| 207 | (boolean #t) | ||
| 208 | "Verbose execution.") | ||
| 209 | (quiet-unsupported? | ||
| 210 | (boolean #t) | ||
| 211 | "Suppress error messages if trim operation (ioctl) is unsupported.") | ||
| 212 | (extra-arguments | ||
| 213 | maybe-list-of-strings | ||
| 214 | "Extra options to append to @command{fstrim} (run @samp{man fstrim} for | ||
| 215 | more information)." | ||
| 216 | (lambda (_ value) | ||
| 217 | (if (maybe-value-set? value) | ||
| 218 | value '()))) | ||
| 219 | (prefix fstrim-)) | ||
| 220 | |||
| 221 | (define (serialize-fstrim-configuration config) | ||
| 222 | (concatenate | ||
| 223 | (filter list? | ||
| 224 | (map (lambda (field) | ||
| 225 | ((configuration-field-serializer field) | ||
| 226 | (configuration-field-name field) | ||
| 227 | ((configuration-field-getter field) config))) | ||
| 228 | fstrim-configuration-fields)))) | ||
| 229 | |||
| 230 | (define (fstrim-mcron-job config) | ||
| 231 | (match-record config <fstrim-configuration> (package schedule) | ||
| 232 | #~(job | ||
| 233 | ;; Note: The “if” below is to ensure that | ||
| 234 | ;; lists are ungexp'd correctly since @var{schedule} | ||
| 235 | ;; can be either a procedure, a string or a list. | ||
| 236 | #$(if (list? schedule) | ||
| 237 | `(list ,@schedule) | ||
| 238 | schedule) | ||
| 239 | (lambda () | ||
| 240 | (system* #$(file-append package "/sbin/fstrim") | ||
| 241 | #$@(serialize-fstrim-configuration config))) | ||
| 242 | "fstrim"))) | ||
| 243 | |||
| 244 | (define fstrim-service-type | ||
| 245 | (service-type | ||
| 246 | (name 'fstrim) | ||
| 247 | (extensions | ||
| 248 | (list (service-extension mcron-service-type | ||
| 249 | (compose list fstrim-mcron-job)))) | ||
| 250 | (description "Discard unused blocks from file systems.") | ||
| 251 | (default-value (fstrim-configuration)))) | ||
| 252 | |||
| 253 | |||
| 254 | ;;; | ||
| 155 | ;;; Kernel module loader. | 255 | ;;; Kernel module loader. |
| 156 | ;;; | 256 | ;;; |
| 157 | 257 | ||
