diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-11-26 22:49:11 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-11-27 08:55:46 +0100 |
commit | 598e19dca1677aebfe235e974f480b5bdd322694 (patch) | |
tree | a894c7f5a56ea04163ea687b01aa1c701d97d73c | |
parent | 9b4d1e7321d04f5d0075810090e72dc16e1578ac (diff) | |
download | patches-598e19dca1677aebfe235e974f480b5bdd322694.tar patches-598e19dca1677aebfe235e974f480b5bdd322694.tar.gz |
system: Build system-wide locale definitions.
* gnu/system/locale.scm: New file.
* gnu-system.am (GNU_SYSTEM_MODULES): Add it.
* gnu/system.scm (<operating-system>)[locale]: Change the default to
"en_US.utf8".
(operating-system-locale-directory): New procecure.
(operating-system-derivation): Use it.
* doc/guix.texi (Using the Configuration System): Change example locale
to "fr_FR.utf8".
(operating-system Reference): Add xref to "Locales". Document
'locale-definitions'.
(Locales): New section.
* po/guix/POTFILES.in: Add gnu/system.scm.
-rw-r--r-- | doc/guix.texi | 86 | ||||
-rw-r--r-- | gnu-system.am | 1 | ||||
-rw-r--r-- | gnu/system.scm | 23 | ||||
-rw-r--r-- | gnu/system/locale.scm | 126 | ||||
-rw-r--r-- | po/guix/POTFILES.in | 1 |
5 files changed, 232 insertions, 5 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index fe1f8a8b76..d4bc74f8a4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -139,6 +139,7 @@ System Configuration * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. * User Accounts:: Specifying user accounts. +* Locales:: Language and cultural convention settings. * Services:: Specifying system services. * Setuid Programs:: Programs running with root privileges. * Initial RAM Disk:: Linux-Libre bootstrapping. @@ -3470,6 +3471,7 @@ instance to support new system services. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. * User Accounts:: Specifying user accounts. +* Locales:: Language and cultural convention settings. * Services:: Specifying system services. * Setuid Programs:: Programs running with root privileges. * Initial RAM Disk:: Linux-Libre bootstrapping. @@ -3496,7 +3498,7 @@ kernel, initial RAM disk, and boot loader looks like this: (operating-system (host-name "komputilo") (timezone "Europe/Paris") - (locale "fr_FR.UTF-8") + (locale "fr_FR.utf8") (bootloader (grub-configuration (device "/dev/sda"))) (file-systems (cons (file-system @@ -3649,9 +3651,13 @@ package}). @item @code{timezone} A timezone identifying string---e.g., @code{"Europe/Paris"}. -@item @code{locale} (default: @code{"en_US.UTF-8"}) -The name of the default locale (@pxref{Locales,,, libc, The GNU C -Library Reference Manual}). +@item @code{locale} (default: @code{"en_US.utf8"}) +The name of the default locale (@pxref{Locale Names,,, libc, The GNU C +Library Reference Manual}). @xref{Locales}, for more information. + +@item @code{locale-definitions} (default: @var{%default-locale-definitions}) +The list of locale definitions to be compiled and that may be used at +run time. @xref{Locales}. @item @code{services} (default: @var{%base-services}) A list of monadic values denoting system services. @xref{Services}. @@ -3958,6 +3964,78 @@ to be present on the system. This includes groups such as ``root'', specific devices such as ``audio'', ``disk'', and ``cdrom''. @end defvr +@node Locales +@subsection Locales + +@cindex locale +A @dfn{locale} defines cultural conventions for a particular language +and region of the world (@pxref{Locales,,, libc, The GNU C Library +Reference Manual}). Each locale has a name that typically has the form +@code{@var{language}_@var{territory}.@var{charset}}---e.g., +@code{fr_LU.utf8} designates the locale for the French language, with +cultural conventions from Luxembourg, and using the UTF-8 encoding. + +@cindex locale definition +Usually, you will want to specify the default locale for the machine +using the @code{locale} field of the @code{operating-system} declaration +(@pxref{operating-system Reference, @code{locale}}). + +That locale must be among the @dfn{locale definitions} that are known to +the system---and these are specified in the @code{locale-definitions} +slot of @code{operating-system}. The default value includes locale +definition for some widely used locales, but not for all the available +locales, in order to save space. + +If the locale specified in the @code{locale} field is not among the +definitions listed in @code{locale-definitions}, @command{guix system} +raises an error. In that case, you should add the locale definition to +the @code{locale-definitions} field. For instance, to add the North +Frisian locale for Germany, the value of that field may be: + +@example +(cons (locale-definition + (name "fy_DE.utf8") (source "fy_DE")) + %default-locale-definitions) +@end example + +Likewise, to save space, one might want @code{locale-definitions} to +list only the locales that are actually used, as in: + +@example +(list (locale-definition + (name "ja_JP.eucjp") (source "ja_JP") + (charset "EUC-JP"))) +@end example + +The @code{locale-definition} form is provided by the @code{(gnu system +locale)} module. Details are given below. + +@deftp {Data Type} locale-definition +This is the data type of a locale definition. + +@table @asis + +@item @code{name} +The name of the locale. @xref{Locale Names,,, libc, The GNU C Library +Reference Manual}, for more information on locale names. + +@item @code{source} +The name of the source for that locale. This is typically the +@code{@var{language}_@var{territory}} part of the locale name. + +@item @code{charset} (default: @code{"UTF-8"}) +The ``character set'' or ``code set'' for that locale, +@uref{http://www.iana.org/assignments/character-sets, as defined by +IANA}. + +@end table +@end deftp + +@defvr {Scheme Variable} %default-locale-definitions +An arbitrary list of commonly used locales, used as the default value of +the @code{locale-definitions} field of @code{operating-system} +declarations. +@end defvr @node Services @subsection Services diff --git a/gnu-system.am b/gnu-system.am index 4c9fcda8b9..bd1ac5d273 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -294,6 +294,7 @@ GNU_SYSTEM_MODULES = \ gnu/system/install.scm \ gnu/system/linux.scm \ gnu/system/linux-initrd.scm \ + gnu/system/locale.scm \ gnu/system/shadow.scm \ gnu/system/vm.scm \ \ diff --git a/gnu/system.scm b/gnu/system.scm index 5c915d3969..8883d3e752 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -46,12 +46,15 @@ #:use-module (gnu services base) #:use-module (gnu system grub) #:use-module (gnu system shadow) + #:use-module (gnu system locale) #:use-module (gnu system linux) #:use-module (gnu system linux-initrd) #:use-module (gnu system file-systems) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:export (operating-system operating-system? @@ -69,6 +72,7 @@ operating-system-packages operating-system-timezone operating-system-locale + operating-system-locale-definitions operating-system-mapped-devices operating-system-file-systems operating-system-activation-script @@ -129,7 +133,9 @@ (timezone operating-system-timezone) ; string (locale operating-system-locale ; string - (default "en_US.UTF-8")) + (default "en_US.utf8")) + (locale-definitions operating-system-locale-definitions ; list of <locale-definition> + (default %default-locale-definitions)) (services operating-system-user-services ; list of monadic services (default %base-services)) @@ -649,6 +655,19 @@ we're running in the final root." #:mapped-devices mapped-devices))) (return #~(string-append #$initrd "/initrd")))) +(define (operating-system-locale-directory os) + "Return the directory containing the locales compiled for the definitions +listed in OS. The C library expects to find it under +/run/current-system/locale." + ;; While we're at it, check whether the locale of OS is defined. + (unless (member (operating-system-locale os) + (map locale-definition-name + (operating-system-locale-definitions os))) + (raise (condition + (&message (message "system locale lacks a definition"))))) + + (locale-directory (operating-system-locale-definitions os))) + (define (kernel->grub-label kernel) "Return a label for the GRUB menu entry that boots KERNEL." (string-append "GNU with " @@ -698,6 +717,7 @@ this file is the reconstruction of GRUB menu entries for old configurations." (boot (operating-system-boot-script os)) (kernel -> (operating-system-kernel os)) (initrd (operating-system-initrd-file os)) + (locale (operating-system-locale-directory os)) (params (operating-system-parameters-file os))) (file-union "system" `(("boot" ,#~#$boot) @@ -705,6 +725,7 @@ this file is the reconstruction of GRUB menu entries for old configurations." ("parameters" ,#~#$params) ("initrd" ,initrd) ("profile" ,#~#$profile) + ("locale" ,#~#$locale) ;used by libc ("etc" ,#~#$etc))))) ;;; system.scm ends here diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm new file mode 100644 index 0000000000..9c5c4d2fd9 --- /dev/null +++ b/gnu/system/locale.scm @@ -0,0 +1,126 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 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 compression) + #:use-module (srfi srfi-26) + #: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 'localdef' 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* (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 #$@(map (cut localedef-command <> #:libc libc) + locales))))) + + (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 + (name (string-append name* ".utf8")) + (source name*) + (charset "UTF-8"))))) + (utf8-locales (syntax-rules () + ((_ name ...) + (list (utf8-locale name) ...))))) + (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 diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 5cc68ff404..591b6a1c9a 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -1,6 +1,7 @@ # List of source files which contain translatable strings. # This should be source files of the various tools, and not package modules. gnu/packages.scm +gnu/system.scm guix/scripts/build.scm guix/scripts/download.scm guix/scripts/package.scm |