Sorry, the last one didn't generate correctly the locale folder for two
reasons: wrong name for the .mo name, and incomplete path.

>From 37ef6594c6db00595b4e3aec6bcaec3eb9b4e1cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644...@gmail.com>
Date: Sat, 24 Oct 2020 20:36:21 +0200
Subject: [PATCH v4 3/5] system: Do not depend on locale folder generated by
 grub-install.

* gnu/bootloader/grub.scm (define-module): Use (guix packages).
(grub-locale-folder): New computed folder.
(grub-configuration-file)[locale-config]: Use grub-locale-folder only when a
locale is needed.
---
 gnu/bootloader/grub.scm | 49 ++++++++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index f1479024e6..1fe09d01c1 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -25,6 +25,7 @@
 
 (define-module (gnu bootloader grub)
   #:use-module (guix build union)
+  #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (guix store)
   #:use-module (guix utils)
@@ -142,6 +143,24 @@ file with the resolution provided in CONFIG."
             (image->png image #:width width #:height height))
            (_ #f)))))
 
+(define (grub-locale-folder grub)
+  "Generate a folder with the locales from GRUB."
+  (define builder
+    #~(begin
+        (use-modules (ice-9 ftw))
+        (let ((locale (string-append #$grub "/share/locale"))
+              (out    #$output))
+          (mkdir out)
+          (chdir out)
+          (for-each (lambda (lang)
+                      (let ((file (string-append locale "/" lang
+                                                 "/LC_MESSAGES/grub.mo"))
+                            (dest (string-append lang ".mo")))
+                        (when (file-exists? file)
+                          (copy-file file dest))))
+                    (scandir locale)))))
+  (computed-file "grub-boot-locale" builder))
+
 (define* (eye-candy config store-device store-mount-point
                     #:key store-directory-prefix port)
   "Return a gexp that writes to PORT (a port-valued gexp) the 'grub.cfg' part
@@ -402,18 +421,26 @@ menuentry ~s {
                  #:port #~port)))
 
   (define locale-config
-    #~(let ((locale #$(and locale
-                           (locale-definition-source
-                            (locale-name->definition locale)))))
-        (when locale
-          (format port "\
+    (let* ((entry (first all-entries))
+           (device (menu-entry-device entry))
+           (mount-point (menu-entry-device-mount-point entry))
+           (bootloader (bootloader-configuration-bootloader config))
+           (grub (bootloader-package bootloader))
+           (locale-dir (grub-locale-folder grub)))
+
+      #~(let ((locale #$(and locale
+                             (locale-definition-source
+                              (locale-name->definition locale))))
+              (locale-dir #$(and locale (grub-locale-folder grub))))
+          (when locale
+            (format port "\
 # Localization configuration.
-if search --file --set boot_partition /grub/grub.cfg; then
-    set locale_dir=(${boot_partition})/grub/locale
-else
-    set locale_dir=/boot/grub/locale
-fi
-set lang=~a~%" locale))))
+search --file --set ~a
+set locale_dir=~a
+set lang=~a~%"
+                    (string-append locale-dir "/e...@quot.mo")
+                    locale-dir
+                    locale)))))
 
   (define keyboard-layout-config
     (let* ((layout (bootloader-configuration-keyboard-layout config))
-- 
2.28.0

Reply via email to