Locales: Difference between revisions

imported>Pmorch
No edit summary
Change "i18n.supportedLocales" to "i18n.extraLocales" to match other documentation
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
NixOS allows to set the default [https://en.wikipedia.org/wiki/Locale_(computer_software) locale] as well as individual locales in the system configuration file:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  # Mandatory
  i18n.defaultLocale = "en_US.UTF-8";
  # Optionally (BEWARE: requires a different format with the added /UTF-8)
  i18n.extraLocales = ["es_VE.UTF-8/UTF-8"];
  # Optionally
  i18n.extraLocaleSettings = {
    # LC_ALL = "en_US.UTF-8"; # This overrides all other LC_* settings.
    LC_CTYPE = "en_US.UTF8";
    LC_ADDRESS = "es_VE.UTF-8";
    LC_MEASUREMENT = "es_VE.UTF-8";
    LC_MESSAGES = "en_US.UTF-8";
    LC_MONETARY = "es_VE.UTF-8";
    LC_NAME = "es_VE.UTF-8";
    LC_NUMERIC = "en_US.UTF-8";
    LC_PAPER = "es_VE.UTF-8";
    LC_TELEPHONE = "es_VE.UTF-8";
    LC_TIME = "es_VE.UTF-8";
    LC_COLLATE = "es_VE.UTF-8";
  };
</nowiki>
}}
{{nixos:option|i18n.defaultLocale}} will set the language and the character set systemwide to the desired value. Specifically, defaultLocale will define the <code>LANG</code> environment variable.
In addition, with {{nixos:option|i18n.supportedLocales}}, the system will also support Venezuelan Spanish. The value <code>"all"</code> means that all locales supported by Glibc will be installed. A full list of supported locales can be found at https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED.
And in the {{nixos:option|i18n.extraLocaleSettings}}, it is possible to set the LC locales individually. This does allow fine-grained adjustments of the used locales. In the above example a mix of American English and Venezuelan Spanish is used. It is also possible to find these settings at [https://search.nixos.org/options NixOS options]. Just search for i18 locale.
{{note|The setting <code>i18n.supportedLocales</code> requires a different format to <code>i18n.extraLocaleSettings</code>  with the added <code>/UTF-8</code>. Otherwise, your locale settings will likely not work.}}
== Troubleshooting when using nix on non-NixOS linux distributions ==
== Troubleshooting when using nix on non-NixOS linux distributions ==


Line 9: Line 44:
And if that file from the local system is somehow broken:
And if that file from the local system is somehow broken:


<syntaxhighlight lang=bash>
<syntaxhighlight lang="bash">
# May require a one-time installation with: nix-env -iA nixpkgs.glibcLocales
# May require a one-time installation with:
nix profile install nixpkgs#glibcLocales
# Using nix profile
export LOCALE_ARCHIVE="$(nix profile list --json | jq '.elements[] | select(.attrPath? and (.attrPath | type == "string") and (.attrPath | endswith("glibcLocales"))) | .storePaths[0]')/lib/locale/locale-archive"
 
# Legacy usage with `nix-env`: May require a one-time installation with: nix-env -iA nixpkgs.glibcLocales
export LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"
export LOCALE_ARCHIVE="$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive"
</syntaxhighlight>
</syntaxhighlight>


Line 24: Line 67:
}
}
</syntaxhighlight>
</syntaxhighlight>
[[Category:Configuration]]