services: 'dmd-service-type' takes a service name.
[jackhill/guix/guix.git] / gnu / system / locale.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu system locale)
20 #:use-module (guix gexp)
21 #:use-module (guix records)
22 #:use-module (guix packages)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages compression)
25 #:use-module (srfi srfi-26)
26 #:export (locale-definition
27 locale-definition?
28 locale-definition-name
29 locale-definition-source
30 locale-definition-charset
31
32 locale-directory
33
34 %default-locale-definitions))
35
36 ;;; Commentary:
37 ;;;
38 ;;; Locale definitions, and compilation thereof.
39 ;;;
40 ;;; Code:
41
42 (define-record-type* <locale-definition> locale-definition
43 make-locale-definition
44 locale-definition?
45 (name locale-definition-name) ;string--e.g., "fr_FR.utf8"
46 (source locale-definition-source) ;string--e.g., "fr_FR"
47 (charset locale-definition-charset ;string--e.g., "UTF-8"
48 (default "UTF-8")))
49
50 (define* (localedef-command locale
51 #:key (libc (canonical-package glibc)))
52 "Return a gexp that runs 'localedef' from LIBC to build LOCALE."
53 #~(begin
54 (format #t "building locale '~a'...~%"
55 #$(locale-definition-name locale))
56 (zero? (system* (string-append #$libc "/bin/localedef")
57 "--no-archive" "--prefix" #$output
58 "-i" #$(locale-definition-source locale)
59 "-f" #$(locale-definition-charset locale)
60 (string-append #$output "/"
61 #$(package-version libc) "/"
62 #$(locale-definition-name locale))))))
63
64 (define* (locale-directory locales
65 #:key (libc (canonical-package glibc)))
66 "Return a directory containing all of LOCALES for LIBC compiled.
67
68 Because locale data formats are incompatible when switching from one libc to
69 another, locale data is put in a sub-directory named after the 'version' field
70 of LIBC."
71 (define build
72 #~(begin
73 (mkdir #$output)
74 (mkdir (string-append #$output "/" #$(package-version libc)))
75
76 ;; 'localedef' executes 'gzip' to access compressed locale sources.
77 (setenv "PATH" (string-append #$gzip "/bin"))
78
79 (exit
80 (and #$@(map (cut localedef-command <> #:libc libc)
81 locales)))))
82
83 (gexp->derivation "locale" build
84 #:local-build? #t))
85
86 (define %default-locale-definitions
87 ;; Arbitrary set of locales that are built by default. They are here mostly
88 ;; to facilitate first-time use to some people, while others may have to add
89 ;; a specific <locale-definition>.
90 (letrec-syntax ((utf8-locale (syntax-rules ()
91 ((_ name*)
92 (locale-definition
93 ;; Note: We choose "utf8", which is the
94 ;; "normalized codeset".
95 (name (string-append name* ".utf8"))
96 (source name*)
97 (charset "UTF-8")))))
98 (utf8-locales (syntax-rules ()
99 ((_ name ...)
100 (list (utf8-locale name) ...)))))
101 ;; Add "en_US.UTF-8" for compatibility with Guix 0.8.
102 (cons (locale-definition
103 (name "en_US.UTF-8")
104 (source "en_US")
105 (charset "UTF-8"))
106 (utf8-locales "ca_ES"
107 "cs_CZ"
108 "da_DK"
109 "de_DE"
110 "el_GR"
111 "en_AU"
112 "en_CA"
113 "en_GB"
114 "en_US"
115 "es_AR"
116 "es_CL"
117 "es_ES"
118 "es_MX"
119 "fi_FI"
120 "fr_BE"
121 "fr_CA"
122 "fr_CH"
123 "fr_FR"
124 "ga_IE"
125 "it_IT"
126 "ja_JP"
127 "ko_KR"
128 "nb_NO"
129 "nl_NL"
130 "pl_PL"
131 "pt_PT"
132 "ro_RO"
133 "ru_RU"
134 "sv_SE"
135 "tr_TR"
136 "uk_UA"
137 "vi_VN"
138 "zh_CN"))))
139
140 ;;; locale.scm ends here