Subject: [PATCH v5 1/3] services: activation: Continue on exceptions.

From: Hilton Chain <[email-masked]>
Date: Sat, 3 May 2025 22:22:55 +0800

* gnu/services.scm (activation-script): Restore current module after
execution.
Catch exception and print the error.
Warn about failed activation script.

Change-Id: I89be31433fbb46d0c4a9dc6115ab167910840b6f
---
 gnu/services.scm | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/gnu/services.scm b/gnu/services.scm
index 8a4002e072..6865c7560f 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -697,10 +697,15 @@ (define (activation-script 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 +725,22 @@ (define (activation-script gexps)
 
                       ;; 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
+                                        (resolve-module '(guile-user)))
+                                       (primitive-load action)))))
+                                '#$actions)))))
 
 (define (gexps->activation-gexp gexps)
   "Return a gexp that runs the activation script containing GEXPS."

base-commit: f76b9c4fdf88cbab81e3cac27841a6c56e3e32c9
prerequisite-patch-id: cc1917ae421a9d5e5e737ab0d7d64eafb80c66ea
prerequisite-patch-id: f25b46e1e08ed9a23bafd4547b30559e87aafc83
prerequisite-patch-id: ebfbf78c71e216e14009a9c619502d515bd301e9
prerequisite-patch-id: 4debf0c53a034e80221112c95ed3572f436ed5b6
prerequisite-patch-id: 4e2979d172c82620e1f423201034aa00610ea22f
prerequisite-patch-id: c411a74b430b78540a70d5516623bd92508e1505
prerequisite-patch-id: eb5d2e8f4679f970898c2b0f1a0caf6dc941712a
prerequisite-patch-id: 1ad337c9c9741592793782f97db490bba02d3c4b
prerequisite-patch-id: 9cdff9105c25033e7eabe7e3af945b73a6e27baf
prerequisite-patch-id: 9c9fb5429cf6568ca848ab804448a2149f861dcd
prerequisite-patch-id: a5c937590b38c4fb5c75a5098f15d2d3d0825a1d
prerequisite-patch-id: fc9f5e958c9f6fcd546278cb2682c0eada7fe99c
prerequisite-patch-id: a1f459ba99139e5a6c6948f9ce783f4e2fa96131
prerequisite-patch-id: 663bb408102bcb62ea42fe8d36ef68c1aacf677a
prerequisite-patch-id: 47cad111e0bfc95219c9884929699f8976defa8d
prerequisite-patch-id: 4c10ae2199d139567a4ac6a22826824d009087b2
prerequisite-patch-id: 6622dcd13c5613309b5a13b4afcc409071940e73
prerequisite-patch-id: 56f9b4474c3aed2ce6b70db5dbf2dddc65636e84
prerequisite-patch-id: 22ae8c4ef90cc288ad4708d82fc01eb51ac751c7
prerequisite-patch-id: 425ed1686582d84d0dd9413e1f599a1154a96cf8
prerequisite-patch-id: e04b6297ce6f820e5a85ed4536d031cd3e6ec4eb
prerequisite-patch-id: 0b35242341e3757c7c4bd1ca9f2cdf25e277d14f
prerequisite-patch-id: ce9b1c2e1ae5360fd5251fd07de5ba268ddaef7a
prerequisite-patch-id: b5225a119bad4fdf39d06f5701e3e49ffc066998
prerequisite-patch-id: 6d4f77830ff3ebda5ed6c7f44418d6408b31a37b
prerequisite-patch-id: 5cb39fe4ecd79203f047f28213fba8e02a848c56
prerequisite-patch-id: 387e1203c97c955dfb5401e0aea691728efdc8ec
prerequisite-patch-id: 6b92abaf6d03b37b9c58bb31285976020b8e2660
prerequisite-patch-id: 56445d57ac941146c2072128c1687464e368c3a6
prerequisite-patch-id: 530734d3059fda18c4c451205f9d87f00082311c
prerequisite-patch-id: f3d353c1a0485f92f2a6c4313d81658f221eb1e0
prerequisite-patch-id: 8b69b664302b49b18bd1471896caa8cde85d47aa
prerequisite-patch-id: b6b409d970f76ec2d7e5c7afe8b9cffa098d9ed9
prerequisite-patch-id: c95d325c498d84ccfa0e89d4203f382c96d69e94
prerequisite-patch-id: 392d2d9a75b67487c555ec8ba3a4421e876e439a
prerequisite-patch-id: ba73d2e1125336400aa53df28bba9f8abadf8160
prerequisite-patch-id: daede4456cc6b3762235fb18cf66358fa7753c6c
prerequisite-patch-id: 72156f437e320f38d277a77acc6c01028a9e4478
prerequisite-patch-id: 275225a32b3c0e811f8d29f7553b1e2564bf05c1
prerequisite-patch-id: 5cda15241e08cc131f2a9e2dad6fadf7cb9aa401
prerequisite-patch-id: 35ab532c7ebece8b456f887db0b73d6c4ecf6123
prerequisite-patch-id: 408888e0206e5b48ffe7ee3cdb310cbd60af6c9d
prerequisite-patch-id: 21823b7c985ebd2c8fe851dee70e6ee446d52722
prerequisite-patch-id: 58104871305201643f59467c8099ccb0d81e9b46
prerequisite-patch-id: 5a24da7fc42b031cb7ba6a8e357bc5784eb1eeb8
prerequisite-patch-id: 6cfcc714847ea9f1cdbaa383a4627748e7489c0b
prerequisite-patch-id: c7df92a41a01831efd7d95b768a86792237d27e8
prerequisite-patch-id: 8231dfd1b56d91e60552f1c69eaecfdb80d56d0e
prerequisite-patch-id: 615a0e10ba14ea1ad96e4400c010897969286d4f
prerequisite-patch-id: 7e751f2eea2a12308b31912317f362dca5eedb2d
prerequisite-patch-id: 5ef7b38b8ff16a89acc64aa0b081667e2eab7f59
prerequisite-patch-id: 9f7a85f3af0e0de60a15c53fcc2e7312504b22da
prerequisite-patch-id: 4f54871424a11496b6f22047879b7b1a879cdd0b
prerequisite-patch-id: 5f587eb497b401e4d1cb36ef125a2ad771383d94
prerequisite-patch-id: 3fe2d0a7bec6162ae31bea45170c7a08c74aef03
prerequisite-patch-id: 6822c6afc981afcc328a8038acf108936f3c2ad5
prerequisite-patch-id: aa54cee74f45c3bb993390f27193ded97f1c1ba4
prerequisite-patch-id: c8240934ebb565784a0fc1e71ffad3c4044f6fc0
prerequisite-patch-id: 7b3bb6304aaaec5d1e274a67d974de67235452e6
prerequisite-patch-id: 7d14bd158b6175ca2916a61d766098074b143b86
prerequisite-patch-id: b1e103461e0cde61d52f926bc32a08c17bd17d91
prerequisite-patch-id: 5c21ad1387f40f38112e4338f1a312335bcdcdaa
prerequisite-patch-id: ba2bf871c24b0b3fc05a667e10aedacef9aade39
prerequisite-patch-id: 52ab7ff09e74a4907a71c58c8650d2ae2072507f
prerequisite-patch-id: bbb0491c7dc5558dfcf61ba5915d9ad012603964
prerequisite-patch-id: fc52339c9691de95241ea1e4369b57da5c441305
prerequisite-patch-id: 5beb416f1849eb118a8c93d2d03ac27421f08595
prerequisite-patch-id: 850d5ee576bfe0a0c7748191f8bce69b182563ab
prerequisite-patch-id: 90722f3add5e2fcc1ffc8b4949f05f7177c19df5
prerequisite-patch-id: 71f74cca72acd19e7a376d54b513b449ddf09035
prerequisite-patch-id: 9fca97c11c8f8610c90ec65212415174a5f4d27f
prerequisite-patch-id: 8053b17aa3e33a530e6b0d37badd49ee7a4db2b0
prerequisite-patch-id: f598c9df66d0b752ee63c6730878febbab2a4ab5
prerequisite-patch-id: ae8e3ea6167758962874d9ceefb17cbfc9cd7617
prerequisite-patch-id: 49565ed5626e3cec6c489d1b6fa15a267fd46f03
prerequisite-patch-id: a8ed40466ed7f9e7527af1f10d69618a88169618
prerequisite-patch-id: 106fa00c2c8f69a514960e08701f44040c581844
prerequisite-patch-id: 53ea387ee17ac942f8270920b53033020731f460
prerequisite-patch-id: 14f7b49fc8ec1630c683b5e001b8c2ebf85ce1ba
prerequisite-patch-id: f095ac3675af165fb246161e06589ace2875ff3f
prerequisite-patch-id: dc224dc9c801c3210385e736b2a528f0b68afb45
prerequisite-patch-id: 6e1ab62a449d025fc4818aa99293b3e9156bef85
prerequisite-patch-id: 1f35d1a714a8cd90cbae9e73a7e453202109d9ed
prerequisite-patch-id: 8cb1e632d490cede7604d7257038e1e426a8161f
prerequisite-patch-id: 515e8ecd478fe4c1310b9b216e8ea42afd926755
prerequisite-patch-id: b60a2334fa8f170ea438edb187f4d8be9368207c
prerequisite-patch-id: f0c49685e76400d3f64afedcbfa0b8fb7c45f0ee
prerequisite-patch-id: b057f699ecb836566cf28875aa42295f37f6dbb7
prerequisite-patch-id: e05e6e7a1ed5ab6147c519f3ac36cd8f940a96a7
prerequisite-patch-id: ed0aced460ded457e9cfb41888dbfec3a25ed6d2
prerequisite-patch-id: 831f8c91f388bcecc0a034fede60158c5f1cccc8
prerequisite-patch-id: a5727ce793701715b7d0a4682d05d023d254f360
prerequisite-patch-id: c2b41659d7d020860185d57381e96ba441f2b779
prerequisite-patch-id: 15d4803752c74f543d3b745d61f86d467b89985c
prerequisite-patch-id: 34df6318e5191dec8c1e3f2a0c8f2050e5833f7d
prerequisite-patch-id: a1d9f6e8f6161e30b3cd11daa26a34b38b7b1658
prerequisite-patch-id: 3bb01cdf4161cb014244f345d2aca3a938188eb8
prerequisite-patch-id: 6c902676ca56fb76bbfc1368ad30e483bc2c94b7
prerequisite-patch-id: ad4774cf4068760dd724ed1a0d6742b5509042f2
prerequisite-patch-id: 3788e077c27eb99e1799b9a0c5c408e0f864bf2c
prerequisite-patch-id: bcbaa96fcd93929f76f14ace875131c2bc4dae58
prerequisite-patch-id: 8113d0eea6ce2db54089db233b1de6d3bb5f69b8
prerequisite-patch-id: b5e000ca84ff45d17becf29a255c23270f46cf8e
prerequisite-patch-id: 1be61c03da01808178b244c961536595d68b0b06
prerequisite-patch-id: 482d1be0fcbf2870d1f62dc36541e4c4e1f8b11a
prerequisite-patch-id: e04264a9dd5a997604f738caaaebd72855ea957a
prerequisite-patch-id: 386b738a5326bc9c1bb85cd0749373d8be5ee576
prerequisite-patch-id: aea5ef9868b8f1e5816859411bfc540e34f9f48d
prerequisite-patch-id: f964e86b1b95a9b42399246681a7dadd85b5c187
prerequisite-patch-id: f6dba43ca3b68af313363c6fef72785d457a0667
prerequisite-patch-id: 5aff308e00a975de66f8706a10f76f2c9faa6af8
prerequisite-patch-id: 97b70657b34fe0e82da07aeb5f64957ccfda1442
prerequisite-patch-id: 57ccd7f162b05697106c297f7d76abf0de11e18e
prerequisite-patch-id: 33a8250abf7eeeda92945a647dbea327647e8455
prerequisite-patch-id: 32a51f7bc1baf5cf58397fd0c99bb85b36de9830
prerequisite-patch-id: 3212ab9cf9c4e1dac5c5ced21ce46b126cbfa1cb
prerequisite-patch-id: 211bd0d1a9e6b293f491eced9e4af9843bf3b287
prerequisite-patch-id: 9883bd0d0c6755d6c4e3e3187d89aa072b0b97af
prerequisite-patch-id: d1157e346fb2aabee7d7c169f44f4ab0bf005c4c
prerequisite-patch-id: 43fd2d4ade95aebf0723d0e5015efd26533617d3
prerequisite-patch-id: 5c4cee47c975c28c734dde626519abc41933b195
prerequisite-patch-id: b18bb968707bfadfe1ecc1487c89dfd436479aee
prerequisite-patch-id: e80367a498f5a20eb853973f611d2f69e5ebc5ee
prerequisite-patch-id: c5fd8e7f7f96c87ea0e3827faffa07fa71304728
prerequisite-patch-id: cfc02bc484870a43f2c804fa849abbc3f0512d50
prerequisite-patch-id: 2e03948dc975c98730ac3814ed5702acca7a6fdf
prerequisite-patch-id: 6cd3353026dafeb79460257c2e60703554a447c5
prerequisite-patch-id: 4111053abab6f41ebda2958d4d7d73ea16eb5283
prerequisite-patch-id: be434332d589b9075b1ac1367c3fd3aa98cf767e
prerequisite-patch-id: eb1ad1c2b4bc1ae02ca7a1d1c4935d5c8e7387db
prerequisite-patch-id: be03d391071cf7080a0bd0e306f5bca71171071b
prerequisite-patch-id: 4174704d944afa67dd97270c34eda6e9e3af8a2b
prerequisite-patch-id: 849103845d254fc50290a02e597e76977cc27bc9
prerequisite-patch-id: e34ea950e22895e60f0c6785a61a26c30f5b5b7c
prerequisite-patch-id: 2901b0d5cc3c44b1a2cac1b0389cc905f552ae73
prerequisite-patch-id: 61f4d2df2b695a9a7bca127e8abb406f87f6bcbd
prerequisite-patch-id: 1c0de8f100ef0d2b0c087cacf3e61d426d17355e
prerequisite-patch-id: c0f22ac952516dc9c92767c1b1362d2c7ecde0f8
prerequisite-patch-id: e945542c050b7792775e301930ee4aca13f19ef5
prerequisite-patch-id: dd90058fdafed0cfabe398f2f4685a9c06f48102
prerequisite-patch-id: 55c89258f5b3aab45902904aab1198994012c546
prerequisite-patch-id: 6bae0c4b7d121accaf1b772fc8eef9011f6290cc
prerequisite-patch-id: d8993f4ad264e89c3e3c8417b309798382532bec
prerequisite-patch-id: 13e40673865c0f57e5b8be99047166ed82250e3f
prerequisite-patch-id: 38c9ea11080cc107addf8eb43fed800fec7e650c
prerequisite-patch-id: 43d07afd567e55d35643c2a59bfd27a88c5b8c33
prerequisite-patch-id: 3a87236411d1231ff88579e2049db124dfb13fbc
prerequisite-patch-id: 0d323a6fdd6b3f4d7ff54eeb161d8d1aec5c3095
prerequisite-patch-id: 27c6d434d2ce44528cd18e35a6e35e1519356f4f
prerequisite-patch-id: ca6c92c390a3088479121fe41529bbaa50e696d1
prerequisite-patch-id: 5b60c7f4831891c18dbf65a02cfc3f2128450b23
prerequisite-patch-id: 13158067cff07251a1beee6337a6fda6abd065b7
prerequisite-patch-id: 92fa2a1323787511222459ff6304e1ec89e1dca9
prerequisite-patch-id: a2374551976025342d152f9cb2997c2df43e69d1
prerequisite-patch-id: 372afb9a7bcfbaa7c2db0093b7a9cf68e5b6fefd
prerequisite-patch-id: a3b0542e81db2a78bb0cfa478e2fc350b5cbdf96
prerequisite-patch-id: dd6cfd93eb2401fc7d7855c8d9323d39ab8fe605
prerequisite-patch-id: a585bc3d58dfa3366a71b89d46c9d49ce3ddebb1
prerequisite-patch-id: dd7459c37315f6394c6813673f5447f9f5561dd2
prerequisite-patch-id: cf5d250aaad218c44cc6c83f6fb289754de96602
prerequisite-patch-id: 511b60f1388e57dc1a7fabcba4e79eb0a7ace588
prerequisite-patch-id: 4467b67459fe5bb46df30eabd9488139f2f999be
prerequisite-patch-id: cbad6cb30c3ea52876c2f16cb1602f5cb7d686f4
prerequisite-patch-id: b1a6a2bfda1255caa968436ecc4ba62e2ed0255d
prerequisite-patch-id: 6e17d044199dd8b53d8453df2f41ce2404d4838a
prerequisite-patch-id: 9be0aab247366f6db440d26cdab7579466d1f0bf
prerequisite-patch-id: 93f8e6f53779eaaee1a12472f5bb845e18c74a6a
prerequisite-patch-id: cb3ac50fb870cf197a4e3ed2ccfb45a6a28400f1
prerequisite-patch-id: 2579801cc89f3e3e022074a0425fba3d38bbe1de
prerequisite-patch-id: 7174912f7b05011468bc47b2ba8167b0e617a70b
prerequisite-patch-id: 08fa38ca1e61c773052671339b78799f19fb7f60
prerequisite-patch-id: b68df6ad7528101d3fbb1fd44f94472a9c8f4f0a
prerequisite-patch-id: 58297e005e4ad0988bd5dc73cd0149637d5c7032
prerequisite-patch-id: 2c09773480fbfd323433986ec528fcb8019273f9
prerequisite-patch-id: e2846320c8b391ff3fec09e51c31578ee6057268
prerequisite-patch-id: 538047ea2f029dd135319c02ba569c4aab9af38d
prerequisite-patch-id: 4fb73799b5ea902d69ecf15b72e1fecc9903d0bc
prerequisite-patch-id: a3a0146e6686bf6f7804192e1a383239c118717b
prerequisite-patch-id: 8de6616d86785be0088bc210202d375b6d0cf5eb
prerequisite-patch-id: 2f32dcab8b97a4fd210ab5b29b6ebf327861be36
prerequisite-patch-id: 081be41a50854a1397ad6574d995ba444b927a7f
prerequisite-patch-id: 2a631555713d3b74f953673f94877e579045f99c
prerequisite-patch-id: b3d778b43f667e73692e1bd8b8945eaf69540fda
-- 
2.49.0