1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu system locale)
20 #:use-module (guix gexp)
21 #:use-module (guix records)
22 #:use-module (gnu packages base)
23 #:use-module (gnu packages compression)
24 #:use-module (srfi srfi-26)
25 #:export (locale-definition
27 locale-definition-name
28 locale-definition-source
29 locale-definition-charset
33 %default-locale-definitions))
37 ;;; Locale definitions, and compilation thereof.
41 (define-record-type* <locale-definition> locale-definition
42 make-locale-definition
44 (name locale-definition-name) ;string--e.g., "fr_FR.utf8"
45 (source locale-definition-source) ;string--e.g., "fr_FR"
46 (charset locale-definition-charset ;string--e.g., "UTF-8"
49 (define* (localedef-command locale
50 #:key (libc (canonical-package glibc)))
51 "Return a gexp that runs 'localedef' from LIBC to build LOCALE."
53 (format #t "building locale '~a'...~%"
54 #$(locale-definition-name locale))
55 (zero? (system* (string-append #$libc "/bin/localedef")
56 "--no-archive" "--prefix" #$output
57 "-i" #$(locale-definition-source locale)
58 "-f" #$(locale-definition-charset locale)
59 (string-append #$output "/"
60 #$(locale-definition-name locale))))))
62 (define* (locale-directory locales
63 #:key (libc (canonical-package glibc)))
64 "Return a directory containing all of LOCALES compiled."
69 ;; 'localedef' executes 'gzip' to access compressed locale sources.
70 (setenv "PATH" (string-append #$gzip "/bin"))
73 (and #$@(map (cut localedef-command <> #:libc libc)
76 (gexp->derivation "locale" build
79 (define %default-locale-definitions
80 ;; Arbitrary set of locales that are built by default. They are here mostly
81 ;; to facilitate first-time use to some people, while others may have to add
82 ;; a specific <locale-definition>.
83 (letrec-syntax ((utf8-locale (syntax-rules ()
86 (name (string-append name* ".utf8"))
89 (utf8-locales (syntax-rules ()
91 (list (utf8-locale name) ...)))))
126 ;;; locale.scm ends here