Subject: bug#54528: [PATCH] fix store-prefix for menu-entries

From: Stefan Karrmann <[email-masked]>
Date: Thu, 9 Feb 2023 21:05:09 +0100

Dear Maxim Cournoyer,

here is a patch, that fixes the global store-prefix for grub menu-entries

on commit 58a95d599ee5d0dc6419d038b7317e1b77b11519

git apply fix-store-prefix-for-menu-entry.patch

Kind regards,
--
Dr. Stefan Karrmann
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index ecd44e7f3c..048b9ff8fd 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -378,22 +378,25 @@ (define (menu-entry->gexp entry)
           (device-mount-point (menu-entry-device-mount-point entry))
           (multiboot-kernel (menu-entry-multiboot-kernel entry))
           (chain-loader (menu-entry-chain-loader entry)))
+      ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
+      ;; Use the right file names for LINUX and INITRD in case
+      ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
+      ;; separate partition. Then we don't use STORE-DIRECTORY-PREFIX.
+      ;; When STORE-DIRECTORY-PREFIX is defined, prepend it the linux and
+      ;; initrd paths, to allow booting from a Btrfs subvolume.
+      (define (normalize-or-grub path)
+        "Normalize PATH if and only if DEVICE-MOUNT-POINT is \"/\"."
+        (if (and (string? device-mount-point)
+                 (string= "/" device-mount-point))
+            (normalize-file path
+                            device-mount-point
+                            store-directory-prefix)
+            path))
       (cond
        (linux
         (let ((arguments (menu-entry-linux-arguments entry))
-              (linux (normalize-file linux
-                                     device-mount-point
-                                     store-directory-prefix))
-              (initrd (normalize-file (menu-entry-initrd entry)
-                                      device-mount-point
-                                      store-directory-prefix)))
-          ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
-          ;; Use the right file names for LINUX and INITRD in case
-          ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
-          ;; separate partition.
-
-          ;; When STORE-DIRECTORY-PREFIX is defined, prepend it the linux and
-          ;; initrd paths, to allow booting from a Btrfs subvolume.
+              (linux (normalize-or-grub linux))
+              (initrd (normalize-or-grub (menu-entry-initrd entry))))
           #~(format port "menuentry ~s {
   ~a
   linux ~a ~a