Locales

Revision as of 22:55, 21 January 2025 by Jooooscha (talk | contribs) (Add a note about the syntactic differences in setting the supported locales and the extra locale settings)

Notes when setting supportedLocales and extraLocaleSettings

Beaware when setting up your locale variables. The setting i18n.supportedLocales requires a different format to i18n.extraLocaleSettings.

The setting i18n.supportedLocales requries the requires the language string with the added /UTF-8

"en_US.UTF-8/UTF-8"
"nl_NL.UTF-8/UTF-8"

The setting i18n.extraLocaleSettings, however, requires the language string without any suffix.

LC_MESSAGES = "en_US.UTF-8"
LC_TIME = "de_DE.UTF-8"

Otherwise, your locale settings will likely not work.

Troubleshooting when using nix on non-NixOS linux distributions

You may need to set the environmental variable LOCALE_ARCHIVE to point to your system's locale-archive. The following can be added to your .zshenv (zsh) or .profile (bash) and applies to Debian, Red Hat, and Arch derivatives:

export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive

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

# 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"

Enable locale support in Nix shell

To support locales within a Nix shell, for example to get localised command output, you need to do something similar:

pkgs.mkShell {
  # [other code omitted]
  LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
}