localenixos

How to granularly configure locale settings?


On my home laptop running NixOS 19.03, in /etc/nixos/configuration.nix, I use the default locale settings:

  i18n = {
    consoleFont = "Lat2-Terminus16";
    consoleKeyMap = "us";
    defaultLocale = "en_US.UTF-8";
  };

That's the only way I know to control locale settings in NixOS, and it's too broad. I want more granular control, so that I can use a mixture of US English and Colombian Spanish. (That's a consequence of my job, not a personal choice.) Specifically, I need these settings:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=es_CO.UTF-8
LC_TIME=es_CO.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=es_CO.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=es_CO.UTF-8
LC_NAME=es_CO.UTF-8
LC_ADDRESS=es_CO.UTF-8
LC_TELEPHONE=es_CO.UTF-8
LC_MEASUREMENT=es_CO.UTF-8
LC_IDENTIFICATION=es_CO.UTF-8
LC_ALL=

On my work desktop (running Ubuntu 18.04), if I evaluate locale in bash, that's what I see. On my home NixOS system, each of those variables is either set to US English or nothing:

[jeff@jbb-dell:~/nix-jbb]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

I thought maybe I should edit /etc/locale.conf, copying the settings from my work system into it. But when (on the NixOS system) I print that file to screen, it doesn't include any of the above variables except LANG:

[jeff@jbb-dell:~/nix-jbb]$ cat /etc/locale.conf
LANG=en_US.UTF-8

[jeff@jbb-dell:~/nix-jbb]$

Therefore the other variables, like LC_NUMERIC, must be getting set somewhere else. I'm worried that if I edit /etc/locale.conf I'll break my system. Is editing that file the right way to set granular locale information in NixOS? And if not, what is?


Solution

  • The option i18n.extralocalesettings is where to set those. E.g.:

    i18n.extraLocaleSettings = {
      LC_MESSAGES = "en_US.UTF-8";
      LC_TIME = "de_DE.UTF-8";
    }