guix_mirror_bot pushed a commit to branch master
in repository guix.

commit be39b5dee51395aa8acd29d17bc027dba1752443
Author: Benjamin Chabanne <[email protected]>
AuthorDate: Sun Sep 28 14:19:00 2025 +0200

    services: log-rotation: Allow to pass procedure as compression method.
    
        * gnu/services/admin.scm (log-rotation-configuration): Change
        validation method and accept gexp procedure.
    
    Change-Id: I67cd5051a05d211349ecbc66ee3a55ab5b1a5971
    Signed-off-by: Ludovic Courtès <[email protected]>
---
 doc/guix.texi          | 10 +++++----
 gnu/services/admin.scm | 57 +++++++++++++++++++++++++++++---------------------
 2 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 29ededf831..7162a5f06b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21556,10 +21556,10 @@ be a @code{log-rotation-configuration} record, as 
discussed below.
 Available @code{log-rotation-configuration} fields are:
 
 @table @asis
-@item @code{provision} (default: @code{'(log-rotation)}) (type: 
list-of-symbols)
+@item @code{provision} (default: @code{(log-rotation)}) (type: list-of-symbols)
 The name(s) of the log rotation Shepherd service.
 
-@item @code{requirement} (default: @code{'(user-processes)}) (type: 
list-of-symbols)
+@item @code{requirement} (default: @code{(user-processes)}) (type: 
list-of-symbols)
 Dependencies of the log rotation Shepherd service.
 
 @item @code{calendar-event} (type: gexp)
@@ -21570,9 +21570,11 @@ on calendar events.
 @item @code{external-log-files} (default: @code{()}) (type: list-of-strings)
 List of file names, external log files that should also be rotated.
 
-@item @code{compression} (default: @code{zstd}) (type: symbol)
+@item @code{compression} (default: @code{zstd}) (type: gexp-or-symbol)
 The compression method used for rotated log files, one of @code{'none},
-@code{'gzip}, and @code{'zstd}.
+@code{'gzip}, and @code{'zstd}.  Alternatively, it can be a gexp that
+evaluates to a procedure; that procedure gets called with the file to be
+rotated.
 
 @item @code{expiry} (type: gexp-or-integer)
 Age in seconds after which a log file is deleted.
diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index 20e4517c66..6e5d51e7ce 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -123,6 +123,9 @@
 (define (gexp-or-integer? x)
   (or (gexp? x) (integer? x)))
 
+(define (gexp-or-symbol? x)
+  (or (gexp? x) (symbol? x)))
+
 (define-configuration log-rotation-configuration
   (provision
    (list-of-symbols '(log-rotation))
@@ -144,9 +147,10 @@ calendar events."
 rotated."
    empty-serializer)
   (compression
-   (symbol 'zstd)
-   "The compression method used for rotated log files, one of
-@code{'none}, @code{'gzip}, and @code{'zstd}."
+   (gexp-or-symbol 'zstd)
+   "The compression method used for rotated log files, one of @code{'none},
+@code{'gzip}, and @code{'zstd}. Alternatively, it can be a gexp that evaluates
+to a procedure; that procedure gets called with the file to be rotated."
    empty-serializer)
   (expiry
    (gexp-or-integer #~(%default-log-expiry))
@@ -158,27 +162,32 @@ rotated."
    empty-serializer))
 
 (define (log-rotation-shepherd-services config)
-  (list (shepherd-service
-         (provision (log-rotation-configuration-provision config))
-         (requirement (log-rotation-configuration-requirement config))
-         (modules '((shepherd service timer)      ;for 'calendar-event'
-                    (shepherd service log-rotation)))
-         (free-form #~(log-rotation-service
-                       #$(log-rotation-configuration-calendar-event config)
-                       #:provision
-                       '#$(log-rotation-configuration-provision config)
-                       #:requirement
-                       '#$(log-rotation-configuration-requirement config)
-                       #:external-log-files
-                       '#$(log-rotation-configuration-external-log-files
-                           config)
-                       #:compression
-                       '#$(log-rotation-configuration-compression config)
-                       #:expiry
-                       #$(log-rotation-configuration-expiry config)
-                       #:rotation-size-threshold
-                       #$(log-rotation-configuration-size-threshold
-                          config))))))
+  (let* ((compression-raw (log-rotation-configuration-compression config))
+         (compression
+           (if (symbol? compression-raw)
+             #~'#$compression-raw
+             compression-raw)))
+    (list (shepherd-service
+           (provision (log-rotation-configuration-provision config))
+           (requirement (log-rotation-configuration-requirement config))
+           (modules '((shepherd service timer)      ;for 'calendar-event'
+                      (shepherd service log-rotation)))
+           (free-form #~(log-rotation-service
+                         #$(log-rotation-configuration-calendar-event config)
+                         #:provision
+                         '#$(log-rotation-configuration-provision config)
+                         #:requirement
+                         '#$(log-rotation-configuration-requirement config)
+                         #:external-log-files
+                         '#$(log-rotation-configuration-external-log-files
+                             config)
+                         #:compression
+                         #$compression
+                         #:expiry
+                         #$(log-rotation-configuration-expiry config)
+                         #:rotation-size-threshold
+                         #$(log-rotation-configuration-size-threshold
+                            config)))))))
 
 (define log-rotation-service-type
   (service-type

Reply via email to