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) | |
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 fe1f8a8b765..d4bc74f8a43 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -139,6 +139,7 @@ System Configuration | |||
| 139 | * File Systems:: Configuring file system mounts. | 139 | * File Systems:: Configuring file system mounts. |
| 140 | * Mapped Devices:: Block device extra processing. | 140 | * Mapped Devices:: Block device extra processing. |
| 141 | * User Accounts:: Specifying user accounts. | 141 | * User Accounts:: Specifying user accounts. |
| 142 | * Locales:: Language and cultural convention settings. | ||
| 142 | * Services:: Specifying system services. | 143 | * Services:: Specifying system services. |
| 143 | * Setuid Programs:: Programs running with root privileges. | 144 | * Setuid Programs:: Programs running with root privileges. |
| 144 | * Initial RAM Disk:: Linux-Libre bootstrapping. | 145 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
| @@ -3470,6 +3471,7 @@ instance to support new system services. | |||
| 3470 | * File Systems:: Configuring file system mounts. | 3471 | * File Systems:: Configuring file system mounts. |
| 3471 | * Mapped Devices:: Block device extra processing. | 3472 | * Mapped Devices:: Block device extra processing. |
| 3472 | * User Accounts:: Specifying user accounts. | 3473 | * User Accounts:: Specifying user accounts. |
| 3474 | * Locales:: Language and cultural convention settings. | ||
| 3473 | * Services:: Specifying system services. | 3475 | * Services:: Specifying system services. |
| 3474 | * Setuid Programs:: Programs running with root privileges. | 3476 | * Setuid Programs:: Programs running with root privileges. |
| 3475 | * Initial RAM Disk:: Linux-Libre bootstrapping. | 3477 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
| @@ -3496,7 +3498,7 @@ kernel, initial RAM disk, and boot loader looks like this: | |||
| 3496 | (operating-system | 3498 | (operating-system |
| 3497 | (host-name "komputilo") | 3499 | (host-name "komputilo") |
| 3498 | (timezone "Europe/Paris") | 3500 | (timezone "Europe/Paris") |
| 3499 | (locale "fr_FR.UTF-8") | 3501 | (locale "fr_FR.utf8") |
| 3500 | (bootloader (grub-configuration | 3502 | (bootloader (grub-configuration |
| 3501 | (device "/dev/sda"))) | 3503 | (device "/dev/sda"))) |
| 3502 | (file-systems (cons (file-system | 3504 | (file-systems (cons (file-system |
| @@ -3649,9 +3651,13 @@ package}). | |||
| 3649 | @item @code{timezone} | 3651 | @item @code{timezone} |
| 3650 | A timezone identifying string---e.g., @code{"Europe/Paris"}. | 3652 | A timezone identifying string---e.g., @code{"Europe/Paris"}. |
| 3651 | 3653 | ||
| 3652 | @item @code{locale} (default: @code{"en_US.UTF-8"}) | 3654 | @item @code{locale} (default: @code{"en_US.utf8"}) |
| 3653 | The name of the default locale (@pxref{Locales,,, libc, The GNU C | 3655 | The name of the default locale (@pxref{Locale Names,,, libc, The GNU C |
| 3654 | Library Reference Manual}). | 3656 | Library Reference Manual}). @xref{Locales}, for more information. |
| 3657 | |||
| 3658 | @item @code{locale-definitions} (default: @var{%default-locale-definitions}) | ||
| 3659 | The list of locale definitions to be compiled and that may be used at | ||
| 3660 | run time. @xref{Locales}. | ||
| 3655 | 3661 | ||
| 3656 | @item @code{services} (default: @var{%base-services}) | 3662 | @item @code{services} (default: @var{%base-services}) |
| 3657 | A list of monadic values denoting system services. @xref{Services}. | 3663 | 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'', | |||
| 3958 | specific devices such as ``audio'', ``disk'', and ``cdrom''. | 3964 | specific devices such as ``audio'', ``disk'', and ``cdrom''. |
| 3959 | @end defvr | 3965 | @end defvr |
| 3960 | 3966 | ||
| 3967 | @node Locales | ||
| 3968 | @subsection Locales | ||
| 3969 | |||
| 3970 | @cindex locale | ||
| 3971 | A @dfn{locale} defines cultural conventions for a particular language | ||
| 3972 | and region of the world (@pxref{Locales,,, libc, The GNU C Library | ||
| 3973 | Reference Manual}). Each locale has a name that typically has the form | ||
| 3974 | @code{@var{language}_@var{territory}.@var{charset}}---e.g., | ||
| 3975 | @code{fr_LU.utf8} designates the locale for the French language, with | ||
| 3976 | cultural conventions from Luxembourg, and using the UTF-8 encoding. | ||
| 3977 | |||
| 3978 | @cindex locale definition | ||
| 3979 | Usually, you will want to specify the default locale for the machine | ||
| 3980 | using the @code{locale} field of the @code{operating-system} declaration | ||
| 3981 | (@pxref{operating-system Reference, @code{locale}}). | ||
| 3982 | |||
| 3983 | That locale must be among the @dfn{locale definitions} that are known to | ||
| 3984 | the system---and these are specified in the @code{locale-definitions} | ||
| 3985 | slot of @code{operating-system}. The default value includes locale | ||
| 3986 | definition for some widely used locales, but not for all the available | ||
| 3987 | locales, in order to save space. | ||
| 3988 | |||
| 3989 | If the locale specified in the @code{locale} field is not among the | ||
| 3990 | definitions listed in @code{locale-definitions}, @command{guix system} | ||
| 3991 | raises an error. In that case, you should add the locale definition to | ||
| 3992 | the @code{locale-definitions} field. For instance, to add the North | ||
| 3993 | Frisian locale for Germany, the value of that field may be: | ||
| 3994 | |||
| 3995 | @example | ||
| 3996 | (cons (locale-definition | ||
| 3997 | (name "fy_DE.utf8") (source "fy_DE")) | ||
| 3998 | %default-locale-definitions) | ||
| 3999 | @end example | ||
| 4000 | |||
| 4001 | Likewise, to save space, one might want @code{locale-definitions} to | ||
| 4002 | list only the locales that are actually used, as in: | ||
| 4003 | |||
| 4004 | @example | ||
| 4005 | (list (locale-definition | ||
| 4006 | (name "ja_JP.eucjp") (source "ja_JP") | ||
| 4007 | (charset "EUC-JP"))) | ||
| 4008 | @end example | ||
| 4009 | |||
| 4010 | The @code{locale-definition} form is provided by the @code{(gnu system | ||
| 4011 | locale)} module. Details are given below. | ||
| 4012 | |||
| 4013 | @deftp {Data Type} locale-definition | ||
| 4014 | This is the data type of a locale definition. | ||
| 4015 | |||
| 4016 | @table @asis | ||
| 4017 | |||
| 4018 | @item @code{name} | ||
| 4019 | The name of the locale. @xref{Locale Names,,, libc, The GNU C Library | ||
| 4020 | Reference Manual}, for more information on locale names. | ||
| 4021 | |||
| 4022 | @item @code{source} | ||
| 4023 | The name of the source for that locale. This is typically the | ||
| 4024 | @code{@var{language}_@var{territory}} part of the locale name. | ||
| 4025 | |||
| 4026 | @item @code{charset} (default: @code{"UTF-8"}) | ||
| 4027 | The ``character set'' or ``code set'' for that locale, | ||
| 4028 | @uref{http://www.iana.org/assignments/character-sets, as defined by | ||
| 4029 | IANA}. | ||
| 4030 | |||
| 4031 | @end table | ||
| 4032 | @end deftp | ||
| 4033 | |||
| 4034 | @defvr {Scheme Variable} %default-locale-definitions | ||
| 4035 | An arbitrary list of commonly used locales, used as the default value of | ||
| 4036 | the @code{locale-definitions} field of @code{operating-system} | ||
| 4037 | declarations. | ||
| 4038 | @end defvr | ||
| 3961 | 4039 | ||
| 3962 | @node Services | 4040 | @node Services |
| 3963 | @subsection Services | 4041 | @subsection Services |
diff --git a/gnu-system.am b/gnu-system.am index 4c9fcda8b95..bd1ac5d273f 100644 --- a/gnu-system.am +++ b/gnu-system.am | |||
| @@ -294,6 +294,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 294 | gnu/system/install.scm \ | 294 | gnu/system/install.scm \ |
| 295 | gnu/system/linux.scm \ | 295 | gnu/system/linux.scm \ |
| 296 | gnu/system/linux-initrd.scm \ | 296 | gnu/system/linux-initrd.scm \ |
| 297 | gnu/system/locale.scm \ | ||
| 297 | gnu/system/shadow.scm \ | 298 | gnu/system/shadow.scm \ |
| 298 | gnu/system/vm.scm \ | 299 | gnu/system/vm.scm \ |
| 299 | \ | 300 | \ |
diff --git a/gnu/system.scm b/gnu/system.scm index 5c915d39698..8883d3e752c 100644 --- a/gnu/system.scm +++ b/gnu/system.scm | |||
| @@ -46,12 +46,15 @@ | |||
| 46 | #:use-module (gnu services base) | 46 | #:use-module (gnu services base) |
| 47 | #:use-module (gnu system grub) | 47 | #:use-module (gnu system grub) |
| 48 | #:use-module (gnu system shadow) | 48 | #:use-module (gnu system shadow) |
| 49 | #:use-module (gnu system locale) | ||
| 49 | #:use-module (gnu system linux) | 50 | #:use-module (gnu system linux) |
| 50 | #:use-module (gnu system linux-initrd) | 51 | #:use-module (gnu system linux-initrd) |
| 51 | #:use-module (gnu system file-systems) | 52 | #:use-module (gnu system file-systems) |
| 52 | #:use-module (ice-9 match) | 53 | #:use-module (ice-9 match) |
| 53 | #:use-module (srfi srfi-1) | 54 | #:use-module (srfi srfi-1) |
| 54 | #:use-module (srfi srfi-26) | 55 | #:use-module (srfi srfi-26) |
| 56 | #:use-module (srfi srfi-34) | ||
| 57 | #:use-module (srfi srfi-35) | ||
| 55 | #:export (operating-system | 58 | #:export (operating-system |
| 56 | operating-system? | 59 | operating-system? |
| 57 | 60 | ||
| @@ -69,6 +72,7 @@ | |||
| 69 | operating-system-packages | 72 | operating-system-packages |
| 70 | operating-system-timezone | 73 | operating-system-timezone |
| 71 | operating-system-locale | 74 | operating-system-locale |
| 75 | operating-system-locale-definitions | ||
| 72 | operating-system-mapped-devices | 76 | operating-system-mapped-devices |
| 73 | operating-system-file-systems | 77 | operating-system-file-systems |
| 74 | operating-system-activation-script | 78 | operating-system-activation-script |
| @@ -129,7 +133,9 @@ | |||
| 129 | 133 | ||
| 130 | (timezone operating-system-timezone) ; string | 134 | (timezone operating-system-timezone) ; string |
| 131 | (locale operating-system-locale ; string | 135 | (locale operating-system-locale ; string |
| 132 | (default "en_US.UTF-8")) | 136 | (default "en_US.utf8")) |
| 137 | (locale-definitions operating-system-locale-definitions ; list of <locale-definition> | ||
| 138 | (default %default-locale-definitions)) | ||
| 133 | 139 | ||
| 134 | (services operating-system-user-services ; list of monadic services | 140 | (services operating-system-user-services ; list of monadic services |
| 135 | (default %base-services)) | 141 | (default %base-services)) |
| @@ -649,6 +655,19 @@ we're running in the final root." | |||
| 649 | #:mapped-devices mapped-devices))) | 655 | #:mapped-devices mapped-devices))) |
| 650 | (return #~(string-append #$initrd "/initrd")))) | 656 | (return #~(string-append #$initrd "/initrd")))) |
| 651 | 657 | ||
| 658 | (define (operating-system-locale-directory os) | ||
| 659 | "Return the directory containing the locales compiled for the definitions | ||
| 660 | listed in OS. The C library expects to find it under | ||
| 661 | /run/current-system/locale." | ||
| 662 | ;; While we're at it, check whether the locale of OS is defined. | ||
| 663 | (unless (member (operating-system-locale os) | ||
| 664 | (map locale-definition-name | ||
| 665 | (operating-system-locale-definitions os))) | ||
| 666 | (raise (condition | ||
| 667 | (&message (message "system locale lacks a definition"))))) | ||
| 668 | |||
| 669 | (locale-directory (operating-system-locale-definitions os))) | ||
| 670 | |||
| 652 | (define (kernel->grub-label kernel) | 671 | (define (kernel->grub-label kernel) |
| 653 | "Return a label for the GRUB menu entry that boots KERNEL." | 672 | "Return a label for the GRUB menu entry that boots KERNEL." |
| 654 | (string-append "GNU with " | 673 | (string-append "GNU with " |
| @@ -698,6 +717,7 @@ this file is the reconstruction of GRUB menu entries for old configurations." | |||
| 698 | (boot (operating-system-boot-script os)) | 717 | (boot (operating-system-boot-script os)) |
| 699 | (kernel -> (operating-system-kernel os)) | 718 | (kernel -> (operating-system-kernel os)) |
| 700 | (initrd (operating-system-initrd-file os)) | 719 | (initrd (operating-system-initrd-file os)) |
| 720 | (locale (operating-system-locale-directory os)) | ||
| 701 | (params (operating-system-parameters-file os))) | 721 | (params (operating-system-parameters-file os))) |
| 702 | (file-union "system" | 722 | (file-union "system" |
| 703 | `(("boot" ,#~#$boot) | 723 | `(("boot" ,#~#$boot) |
| @@ -705,6 +725,7 @@ this file is the reconstruction of GRUB menu entries for old configurations." | |||
| 705 | ("parameters" ,#~#$params) | 725 | ("parameters" ,#~#$params) |
| 706 | ("initrd" ,initrd) | 726 | ("initrd" ,initrd) |
| 707 | ("profile" ,#~#$profile) | 727 | ("profile" ,#~#$profile) |
| 728 | ("locale" ,#~#$locale) ;used by libc | ||
| 708 | ("etc" ,#~#$etc))))) | 729 | ("etc" ,#~#$etc))))) |
| 709 | 730 | ||
| 710 | ;;; system.scm ends here | 731 | ;;; system.scm ends here |
diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm new file mode 100644 index 00000000000..9c5c4d2fd92 --- /dev/null +++ b/gnu/system/locale.scm | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2014 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 (gnu packages base) | ||
| 23 | #:use-module (gnu packages compression) | ||
| 24 | #:use-module (srfi srfi-26) | ||
| 25 | #:export (locale-definition | ||
| 26 | locale-definition? | ||
| 27 | locale-definition-name | ||
| 28 | locale-definition-source | ||
| 29 | locale-definition-charset | ||
| 30 | |||
| 31 | locale-directory | ||
| 32 | |||
| 33 | %default-locale-definitions)) | ||
| 34 | |||
| 35 | ;;; Commentary: | ||
| 36 | ;;; | ||
| 37 | ;;; Locale definitions, and compilation thereof. | ||
| 38 | ;;; | ||
| 39 | ;;; Code: | ||
| 40 | |||
| 41 | (define-record-type* <locale-definition> locale-definition | ||
| 42 | make-locale-definition | ||
| 43 | 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" | ||
| 47 | (default "UTF-8"))) | ||
| 48 | |||
| 49 | (define* (localedef-command locale | ||
| 50 | #:key (libc (canonical-package glibc))) | ||
| 51 | "Return a gexp that runs 'localdef' from LIBC to build LOCALE." | ||
| 52 | #~(begin | ||
| 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)))))) | ||
| 61 | |||
| 62 | (define* (locale-directory locales | ||
| 63 | #:key (libc (canonical-package glibc))) | ||
| 64 | "Return a directory containing all of LOCALES compiled." | ||
| 65 | (define build | ||
| 66 | #~(begin | ||
| 67 | (mkdir #$output) | ||
| 68 | |||
| 69 | ;; 'localedef' executes 'gzip' to access compressed locale sources. | ||
| 70 | (setenv "PATH" (string-append #$gzip "/bin")) | ||
| 71 | |||
| 72 | (exit | ||
| 73 | (and #$@(map (cut localedef-command <> #:libc libc) | ||
| 74 | locales))))) | ||
| 75 | |||
| 76 | (gexp->derivation "locale" build | ||
| 77 | #:local-build? #t)) | ||
| 78 | |||
| 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 () | ||
| 84 | ((_ name*) | ||
| 85 | (locale-definition | ||
| 86 | (name (string-append name* ".utf8")) | ||
| 87 | (source name*) | ||
| 88 | (charset "UTF-8"))))) | ||
| 89 | (utf8-locales (syntax-rules () | ||
| 90 | ((_ name ...) | ||
| 91 | (list (utf8-locale name) ...))))) | ||
| 92 | (utf8-locales "ca_ES" | ||
| 93 | "cs_CZ" | ||
| 94 | "da_DK" | ||
| 95 | "de_DE" | ||
| 96 | "el_GR" | ||
| 97 | "en_AU" | ||
| 98 | "en_CA" | ||
| 99 | "en_GB" | ||
| 100 | "en_US" | ||
| 101 | "es_AR" | ||
| 102 | "es_CL" | ||
| 103 | "es_ES" | ||
| 104 | "es_MX" | ||
| 105 | "fi_FI" | ||
| 106 | "fr_BE" | ||
| 107 | "fr_CA" | ||
| 108 | "fr_CH" | ||
| 109 | "fr_FR" | ||
| 110 | "ga_IE" | ||
| 111 | "it_IT" | ||
| 112 | "ja_JP" | ||
| 113 | "ko_KR" | ||
| 114 | "nb_NO" | ||
| 115 | "nl_NL" | ||
| 116 | "pl_PL" | ||
| 117 | "pt_PT" | ||
| 118 | "ro_RO" | ||
| 119 | "ru_RU" | ||
| 120 | "sv_SE" | ||
| 121 | "tr_TR" | ||
| 122 | "uk_UA" | ||
| 123 | "vi_VN" | ||
| 124 | "zh_CN"))) | ||
| 125 | |||
| 126 | ;;; locale.scm ends here | ||
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 5cc68ff4041..591b6a1c9ad 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | # List of source files which contain translatable strings. | 1 | # List of source files which contain translatable strings. |
| 2 | # This should be source files of the various tools, and not package modules. | 2 | # This should be source files of the various tools, and not package modules. |
| 3 | gnu/packages.scm | 3 | gnu/packages.scm |
| 4 | gnu/system.scm | ||
| 4 | guix/scripts/build.scm | 5 | guix/scripts/build.scm |
| 5 | guix/scripts/download.scm | 6 | guix/scripts/download.scm |
| 6 | guix/scripts/package.scm | 7 | guix/scripts/package.scm |
