all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob f7e17f86ff444f297fca26a8593440ddced9e103 6418 bytes (raw)
name: gnu/system/locale.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu system locale)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (gnu packages base)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages compression)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)
  #:export (locale-definition
            locale-definition?
            locale-definition-name
            locale-definition-source
            locale-definition-charset

            locale-directory

            %default-locale-definitions))

;;; Commentary:
;;;
;;; Locale definitions, and compilation thereof.
;;;
;;; Code:

(define-record-type* <locale-definition> locale-definition
  make-locale-definition
  locale-definition?
  (name    locale-definition-name)                ;string--e.g., "fr_FR.utf8"
  (source  locale-definition-source)              ;string--e.g., "fr_FR"
  (charset locale-definition-charset              ;string--e.g., "UTF-8"
           (default "UTF-8")))

(define* (localedef-command locale
                            #:key (libc (canonical-package glibc)))
  "Return a gexp that runs 'localedef' from LIBC to build LOCALE."
  #~(begin
      (format #t "building locale '~a'...~%"
              #$(locale-definition-name locale))
      (zero? (system* (string-append #$libc "/bin/localedef")
                      "--no-archive" "--prefix" #$output
                      "-i" #$(locale-definition-source locale)
                      "-f" #$(locale-definition-charset locale)
                      (string-append #$output "/"
                                     #$(locale-definition-name locale))))))

(define (sanity-check locale-data locale)
  "Return an expression that returns true if a program linked against the
current glibc package can read locale data for LOCALE from LOCALE-DATA."
  #~(begin
      (format #t "checking whether current libc can \
load this locale data from '~a'...~%"
              #$locale-data)
      (setenv "LOCPATH" #$locale-data)
      (setenv "LC_ALL" #$locale)

      ;; If this fails with an assertion failure, then this is bad.  See
      ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>
      ;; and <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>.
      ;; We can't check whether (setlocale LC_ALL "") works because it is
      ;; likely to fail, at least because of one locale category whose data
      ;; format has changed incompatibly.
      (zero? (system* (string-append #$(canonical-package glibc)
                                     "/bin/locale")))))

(define* (locale-directory locales
                           #:key (libc (canonical-package glibc)))
  "Return a directory containing all of LOCALES compiled."
  (define build
    #~(begin
        (mkdir #$output)

        ;; 'localedef' executes 'gzip' to access compressed locale sources.
        (setenv "PATH" (string-append #$gzip "/bin"))

        (exit
         (and (system* (string-append #$libc "/bin/localedef") "--version")
              #$@(map (cut localedef-command <> #:libc libc)
                      locales)
              #$(match locales
                  ((first . _)
                   (sanity-check #~#$output
                                 (locale-definition-name first)))
                  (()
                   #t))))))

  (gexp->derivation "locale" build
                    #:local-build? #t))

(define %default-locale-definitions
  ;; Arbitrary set of locales that are built by default.  They are here mostly
  ;; to facilitate first-time use to some people, while others may have to add
  ;; a specific <locale-definition>.
  (letrec-syntax ((utf8-locale (syntax-rules ()
                                 ((_ name*)
                                  (locale-definition
                                   ;; Note: We choose "utf8", which is the
                                   ;; "normalized codeset".
                                   (name (string-append name* ".utf8"))
                                   (source name*)
                                   (charset "UTF-8")))))
                  (utf8-locales (syntax-rules ()
                                  ((_ name ...)
                                   (list (utf8-locale name) ...)))))
    ;; Add "en_US.UTF-8" for compatibility with Guix 0.8.
    (cons (locale-definition
           (name "en_US.UTF-8")
           (source "en_US")
           (charset "UTF-8"))
          (utf8-locales "ca_ES"
                        ;; "cs_CZ"
                        ;; "da_DK"
                        ;; "de_DE"
                        ;; "el_GR"
                        ;; "en_AU"
                        ;; "en_CA"
                        ;; "en_GB"
                        ;; "en_US"
                        ;; "es_AR"
                        ;; "es_CL"
                        ;; "es_ES"
                        ;; "es_MX"
                        ;; "fi_FI"
                        ;; "fr_BE"
                        ;; "fr_CA"
                        ;; "fr_CH"
                        ;; "fr_FR"
                        ;; "ga_IE"
                        ;; "it_IT"
                        ;; "ja_JP"
                        ;; "ko_KR"
                        ;; "nb_NO"
                        ;; "nl_NL"
                        ;; "pl_PL"
                        ;; "pt_PT"
                        ;; "ro_RO"
                        ;; "ru_RU"
                        ;; "sv_SE"
                        ;; "tr_TR"
                        ;; "uk_UA"
                        ;; "vi_VN"
                        "zh_CN"))))

;;; locale.scm ends here

debug log:

solving f7e17f8 ...
found f7e17f8 in https://yhetil.org/guix/87k2rfwrf9.fsf@inria.fr/
found 393dd42 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 393dd42354aa6e6809281c074945241a87e95d24	gnu/system/locale.scm

applying [1/1] https://yhetil.org/guix/87k2rfwrf9.fsf@inria.fr/
diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm
index 393dd42..f7e17f8 100644

Checking patch gnu/system/locale.scm...
Applied patch gnu/system/locale.scm cleanly.

index at:
100644 f7e17f86ff444f297fca26a8593440ddced9e103	gnu/system/locale.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.