diff mbox series

[bug#44075] gnu: Add make-glibc-locales-collection.

Message ID 20201019064739.4736-1-efraim@flashner.co.il
State New
Headers show
Series [bug#44075] gnu: Add make-glibc-locales-collection. | expand

Checks

Context Check Description
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Efraim Flashner Oct. 19, 2020, 6:47 a.m. UTC
* gnu/packages/base.scm (make-glibc-locales-collection): New macro.
(en_us-glibc-locales): New variable.
---
 gnu/packages/base.scm | 73 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)

Comments

Miguel Arruga Vivas Oct. 19, 2020, 1:17 p.m. UTC | #1
Hi Efraim,

I've been taking a look into your patch.  One issue are the comments
about utf8 and UTF-8, as the issue is already explained in
make-glibc[-utf8]-locales.

Other point is:

Efraim Flashner <efraim@flashner.co.il> writes:
> +(define* (make-glibc-locales-collection
> +           glibc
> +           #:optional (locales
> +                        '(list "en_US.utf8" "en_US.ISO-8859-1")))
> (... Removed for clarity ...)
> +             ,locales)

I would have used list there like (list ,@locales) or '(,@locales), this
looks a bit odd to my eyes at least.  I'd expect this kind of calling code:

(let ((locales '("de_CH.utf8" ... "de_DE.utf8"))
      (my-glibc ...))
  (make-glibc-locales-collection myglibc locales))

Enforcing an extra quotation for no real reason on the calling site, as
strings are self-evaluating objects, and the use of the symbol list,
whose meaning depends on other context of execution, doesn't seem
necessary.  Even worse, my example would raise an error as "de_CH.utf8"
is not a procedure.

What do you think about replacing make-glibc-utf8-locales with a call of
the new function (using that code) ensuring that the generated
derivation stays the same for that case (i.e. it's optimized for the
UTF-8 case)?

Happy hacking!
Miguel
ashish.is--- via Guix-patches" via Dec. 24, 2020, 9:38 a.m. UTC | #2
Could the en_SE.utf8 locale be added? For those who want their system in English, but with YMD date and 24 hour time.
Leo Famulari Dec. 24, 2020, 10:04 p.m. UTC | #3
On Thu, Dec 24, 2020 at 09:38:51AM +0000, bdju--- via Guix-patches via wrote:
> Could the en_SE.utf8 locale be added? For those who want their system in English, but with YMD date and 24 hour time.

Is this contained in the glibc-locales package?

The glibc-utf8-locales package is basically just a small package variant
for testing and we are planning to remove it completely.
Leo Famulari Dec. 24, 2020, 10:05 p.m. UTC | #4
On Thu, Dec 24, 2020 at 05:04:41PM -0500, Leo Famulari wrote:
> On Thu, Dec 24, 2020 at 09:38:51AM +0000, bdju--- via Guix-patches via wrote:
> > Could the en_SE.utf8 locale be added? For those who want their system in English, but with YMD date and 24 hour time.
> 
> Is this contained in the glibc-locales package?
> 
> The glibc-utf8-locales package is basically just a small package variant
> for testing and we are planning to remove it completely.

I read more of this thread and realized I misunderstood its point.
Please disregard my previous message.
diff mbox series

Patch

diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index c83775d8ee..41d3aaf865 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -62,7 +62,8 @@ 
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:export (glibc
-            libiconv-if-needed))
+            libiconv-if-needed
+            make-custom-glibc-locales))
 
 ;;; Commentary:
 ;;;
@@ -1106,6 +1107,69 @@  to the @code{share/locale} sub-directory of this package.")
                                         ,(version-major+minor
                                           (package-version glibc)))))))))))
 
+(define* (make-glibc-locales-collection
+           glibc
+           #:optional (locales
+                        '(list "en_US.utf8" "en_US.ISO-8859-1")))
+                        ;; This list for testing
+                        ;'(list "el_GR.UTF-8" "en_US.utf8" "he_IL.ISO-8859-8" "ja_JP.EUC-JP" "zh_CN.GB18030" "zh_CN.GBK" "hy_AM.ARMSCII-8")))
+  (package
+    (name "glibc-locales-collection")
+    (version (package-version glibc))
+    (source #f)
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+
+         (let* ((libc      (assoc-ref %build-inputs "glibc"))
+                (gzip      (assoc-ref %build-inputs "gzip"))
+                (out       (assoc-ref %outputs "out"))
+                (localedir (string-append out "/lib/locale/"
+                                          ,(version-major+minor version))))
+           ;; 'localedef' needs 'gzip'.
+           (setenv "PATH" (string-append libc "/bin:" gzip "/bin"))
+
+           (mkdir-p localedir)
+           (for-each
+             (lambda (locale)
+               (let* ((contains-dot? (string-index locale #\.))
+                      (encoding-type (substring locale (1+ contains-dot?)))
+                      (raw-locale    (substring locale 0 contains-dot?))
+                      (utf8? (or (number? (string-contains locale ".utf8"))
+                                 (number? (string-contains locale ".UTF-8"))))
+                      (file (if utf8?
+                              (string-append localedir "/" raw-locale ".utf8")
+                              (if (string-contains locale ".ISO")
+                                (string-append localedir "/" raw-locale)
+                                (string-append localedir "/" locale)))))
+
+                 (invoke "localedef" "--no-archive"
+                         "--prefix" localedir
+                         "-i" raw-locale
+                         "-f" (if (equal? "utf8" encoding-type)
+                                "UTF-8"
+                                encoding-type)
+                         file)
+
+                 ;; Is it utf8 or UTF-8? NO ONE KNOWS!
+                 (when utf8?
+                   (symlink (string-append raw-locale ".utf8")
+                            (string-append localedir "/"
+                                           raw-locale ".UTF-8")))))
+             ,locales)
+           #t))))
+    (native-inputs `(("glibc" ,glibc)
+                     ("gzip" ,gzip)))
+    (synopsis "Customizable collection of locales")
+    (description
+     "This package provides a custom collection of locales useful for
+providing exactly the locales requested when size matters.")
+    (home-page (package-home-page glibc))
+    (license (package-license glibc))))
+
 (define-public (make-glibc-utf8-locales glibc)
   (package
     (name "glibc-utf8-locales")
@@ -1161,6 +1225,13 @@  test environments.")
 (define-public glibc-utf8-locales
   (make-glibc-utf8-locales glibc))
 
+(define-public en_us-glibc-locales
+  (package
+    (inherit (make-glibc-locales-collection
+               glibc
+               '(list "en_US.utf8" "en_US.ISO-8859-1")))
+    (name "en-us-glibc-locales")))
+
 ;; Packages provided to ease use of binaries linked against the previous libc.
 (define-public glibc-locales-2.29
   (package (inherit (make-glibc-locales glibc-2.29))