From 9d9a6291c4e61f3af71e94e549926bd9905e99db Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Sat, 3 May 2025 22:38:28 +0800 Subject: [PATCH] services: activation: Continue on exceptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/services.scm (activation-script): Reset environment before loading activation script. Catch exception and print the error. Warn about failed activation script. Change-Id: I89be31433fbb46d0c4a9dc6115ab167910840b6f Signed-off-by: Maxim Cournoyer Reviewed-by: Ludovic Courtès --- gnu/services.scm | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/gnu/services.scm b/gnu/services.scm index 8a4002e072462e9249b030316529a2b775d014b0..af054339fd9d1c4f2579246f2e3fcaffa6c59556 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -692,15 +692,31 @@ ACTIVATION-SCRIPT-TYPE." (define (activation-script gexps) "Return the system's activation script, which evaluates GEXPS." (define actions - (map (cut program-file "activate-service.scm" <>) gexps)) + ;; TODO: Instead of importing modules here, let users of activation service + ;; add them explicitly. See . + (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) + (srfi srfi-34)) (mkdir-p "/var/run") ;; Make sure the user accounting database exists. If it @@ -720,7 +736,22 @@ ACTIVATION-SCRIPT-TYPE." ;; 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. + (guard (condition + (else + (format (current-error-port) "~a~%" + condition) + (warning + (G_ "failed to activate '~a'~%") + action))) + (save-module-excursion + (lambda () + (set-current-module + (make-fresh-user-module)) + (primitive-load action))))) + '#$actions))))) (define (gexps->activation-gexp gexps) "Return a gexp that runs the activation script containing GEXPS."