[bug#73494,v2,3/3] services: activation: Continue on exceptions.

Message ID 317ca0d525d3f2c668a9ec2c5357b3ca924ee1a7.1741228110.git.hako@ultrarare.space
State New
Headers
Series tmpfs /run |

Commit Message

Hilton Chain March 6, 2025, 2:38 a.m. UTC
  Use ‘invoke’ for backtraces and avoid changing environment.

* gnu/services.scm (activation-script): Execute activation scripts in
‘invoke’.
Warn about failed activation scripts.

Change-Id: I89be31433fbb46d0c4a9dc6115ab167910840b6f
---
 gnu/services.scm | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gnu/services.scm b/gnu/services.scm
index 7805cae971..3a511a42e5 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -690,15 +690,28 @@  (define* (activation-service->script service)
 (define (activation-script gexps)
   "Return the system's activation script, which evaluates GEXPS."
   (define actions
-    (map (cut program-file "activate-service.scm" <>) gexps))
+    (map (lambda (action)
+           (program-file "activate-service.scm"
+                         (with-imported-modules (source-module-closure
+                                                 '((gnu build activation)
+                                                   (guix build utils)))
+                           #~(begin
+                               (use-modules (gnu build activation)
+                                            (guix build utils))
+                               #$action))))
+         gexps))
 
   (program-file "activate.scm"
                 (with-imported-modules (source-module-closure
                                         '((gnu build activation)
-                                          (guix build utils)))
+                                          (guix build utils)
+                                          (guix diagnostics)
+                                          (guix i18n)))
                   #~(begin
                       (use-modules (gnu build activation)
-                                   (guix build utils))
+                                   (guix build utils)
+                                   (guix diagnostics)
+                                   (guix i18n))
 
                       (mkdir-p "/var/run")
                       ;; Make sure the user accounting database exists.  If it
@@ -717,8 +730,17 @@  (define (activation-script gexps)
                       (activate-current-system)
 
                       ;; Run the services' activation snippets.
-                      ;; TODO: Use 'load-compiled'.
-                      (for-each primitive-load '#$actions)))))
+                      (for-each (lambda (action)
+                                  ;; Don't block activation process when one
+                                  ;; action fails.
+                                  (catch #t
+                                    (lambda ()
+                                      (invoke action))
+                                    (lambda _
+                                      (warning
+                                       (G_ "failed to activate '~a'.~%")
+                                       action))))
+                                '#$actions)))))
 
 (define (gexps->activation-gexp gexps)
   "Return a gexp that runs the activation script containing GEXPS."