Subject: [bug#28399] [PATCH 1/2] services: mysql: Fix missing modules on activation.

From: Christopher Baines <[email-masked]>
Date: Sun, 8 Oct 2017 10:06:07 +0100

On Wed, 20 Sep 2017 11:21:51 +0200
[email-masked] (Ludovic Courtès) wrote:

> As you can see,
> /gnu/store/9whwwppmb2sjfsy0967s627bzgdfl8bc-guile-static-stripped-2.2.2/share/guile/2.2,
> which is at the tail of %load-path, is missing from the root file
> system, hence the failure.
> 
> To work around it, we’d have to either ensure that
> ‘guile-static-stripped’ is on the root file system, or adjust the load
> path when we switch roots, or (simplest solution) pre-load (ice-9
> popen) before ‘switch-root’.
> 
> To be continued…

Awesome investigation Ludo. This explanation could match what I was
experiencing when using the mysql service on GuixSD. Sometimes after
running guix gc, the system wouldn't boot. This could have been because
the guile package needed by the initrd was removed from the store.

Given that the initrd has a dependency on this guile, but it doesn't
reference it because its compressed, how about adding a explicit
reference to the guile used? I've attached a patch, and this looks to
fix the issue as far as the mysql service is concerned.
From f313f80407039efb215c18de99ee36696528e98a Mon Sep 17 00:00:00 2001
From: Christopher Baines <[email-masked]>
Date: Sun, 8 Oct 2017 09:52:24 +0100
Subject: [PATCH] linux-initrd: Ensure that the guile used in the initrd
 referenced.

By referencing guile from the initrd, it will be present in the store when
this initrd is used. If the exact guile used within the initrd isn't present
in the store, then after root is switched during the boot process, loading
modules (such as (ice-9 popen)) won't work.

* gnu/system/linux-initrd.scm (expression->initrd)[builder]: Write out a file
  called references in to the initrd derivation, which includes the store path
  for guile.
---
 gnu/system/linux-initrd.scm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 5a7aec5c8..c869bba5f 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -78,6 +78,19 @@ the derivations referenced by EXP are automatically copied to the initrd."
           (use-modules (gnu build linux-initrd))
 
           (mkdir #$output)
+
+          ;; Due to the compression, the references to the dependencies are
+          ;; obscured, so write them out uncompressed to a file.
+          (call-with-output-file (string-append #$ output "/references")
+            (lambda (port)
+              (map (lambda (reference)
+                     (simple-format port "~A\n" reference))
+                   (list
+                    ;; The guile used in the initrd must be present in the
+                    ;; store, so that module loading works once the root is
+                    ;; switched.
+                    #$guile))))
+
           (build-initrd (string-append #$output "/initrd")
                         #:guile #$guile
                         #:init #$init
-- 
2.14.2