Next: , Previous: , Up: System Configuration   [Contents][Index]


7.2.6 Locales

A locale defines cultural conventions for a particular language and region of the world (see Locales in The GNU C Library Reference Manual). Each locale has a name that typically has the form language_territory.codeset—e.g., fr_LU.utf8 designates the locale for the French language, with cultural conventions from Luxembourg, and using the UTF-8 encoding.

Usually, you will want to specify the default locale for the machine using the locale field of the operating-system declaration (see locale).

That locale must be among the locale definitions that are known to the system—and these are specified in the locale-definitions slot of 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 locale field is not among the definitions listed in locale-definitions, guix system raises an error. In that case, you should add the locale definition to the locale-definitions field. For instance, to add the North Frisian locale for Germany, the value of that field may be:

(cons (locale-definition
        (name "fy_DE.utf8") (source "fy_DE"))
      %default-locale-definitions)

Likewise, to save space, one might want locale-definitions to list only the locales that are actually used, as in:

(list (locale-definition
        (name "ja_JP.eucjp") (source "ja_JP")
        (charset "EUC-JP")))

The compiled locale definitions are available at /run/current-system/locale/X.Y, where X.Y is the libc version, which is the default location where the GNU libc provided by Guix looks for locale data. This can be overridden using the LOCPATH environment variable (see LOCPATH and locale packages).

The locale-definition form is provided by the (gnu system locale) module. Details are given below.

Data Type: locale-definition

This is the data type of a locale definition.

name

The name of the locale. See Locale Names in The GNU C Library Reference Manual, for more information on locale names.

source

The name of the source for that locale. This is typically the language_territory part of the locale name.

charset (default: "UTF-8")

The “character set” or “code set” for that locale, as defined by IANA.

Scheme Variable: %default-locale-definitions

An arbitrary list of commonly used UTF-8 locales, used as the default value of the locale-definitions field of operating-system declarations.

These locale definitions use the normalized codeset for the part that follows the dot in the name (see normalized codeset in The GNU C Library Reference Manual). So for instance it has uk_UA.utf8 but not, say, uk_UA.UTF-8.

7.2.6.1 Locale Data Compatibility Considerations

operating-system declarations provide a locale-libcs field to specify the GNU libc packages that are used to compile locale declarations (see operating-system Reference). “Why would I care?”, you may ask. Well, it turns out that the binary format of locale data is occasionally incompatible from one libc version to another.

For instance, a program linked against libc version 2.21 is unable to read locale data produced with libc 2.22; worse, that program aborts instead of simply ignoring the incompatible locale data18. Similarly, a program linked against libc 2.22 can read most, but not all, the locale data from libc 2.21 (specifically, LC_COLLATE data is incompatible); thus calls to setlocale may fail, but programs will not abort.

The “problem” in GuixSD is that users have a lot of freedom: They can choose whether and when to upgrade software in their profiles, and might be using a libc version different from the one the system administrator used to build the system-wide locale data.

Fortunately, unprivileged users can also install their own locale data and define GUIX_LOCPATH accordingly (see GUIX_LOCPATH and locale packages).

Still, it is best if the system-wide locale data at /run/current-system/locale is built for all the libc versions actually in use on the system, so that all the programs can access it—this is especially crucial on a multi-user system. To do that, the administrator can specify several libc packages in the locale-libcs field of operating-system:

(use-package-modules base)

(operating-system
  ;; …
  (locale-libcs (list glibc-2.21 (canonical-package glibc))))

This example would lead to a system containing locale definitions for both libc 2.21 and the current version of libc in /run/current-system/locale.


Footnotes

(18)

Versions 2.23 and later of GNU libc will simply skip the incompatible locale data, which is already an improvement.


Next: , Previous: , Up: System Configuration   [Contents][Index]