1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6 ###### interface
7
8 options = {
9
10 i18n = {
11 glibcLocales = mkOption {
12 type = types.path;
13 default = pkgs.buildPackages.glibcLocales.override {
14 allLocales = any (x: x == "all") config.i18n.supportedLocales;
15 locales = config.i18n.supportedLocales;
16 };
17 example = literalExample "pkgs.glibcLocales";
18 description = ''
19 Customized pkg.glibcLocales package.
20
21 Changing this option can disable handling of i18n.defaultLocale
22 and supportedLocale.
23 '';
24 };
25
26 defaultLocale = mkOption {
27 type = types.str;
28 default = "en_US.UTF-8";
29 example = "nl_NL.UTF-8";
30 description = ''
31 The default locale. It determines the language for program
32 messages, the format for dates and times, sort order, and so on.
33 It also determines the character set, such as UTF-8.
34 '';
35 };
36
37 extraLocaleSettings = mkOption {
38 type = types.attrsOf types.str;
39 default = {};
40 example = { LC_MESSAGES = "en_US.UTF-8"; LC_TIME = "de_DE.UTF-8"; };
41 description = ''
42 A set of additional system-wide locale settings other than
43 <literal>LANG</literal> which can be configured with
44 <option>i18n.defaultLocale</option>.
45 '';
46 };
47
48 supportedLocales = mkOption {
49 type = types.listOf types.str;
50 default = ["all"];
51 example = ["en_US.UTF-8/UTF-8" "nl_NL.UTF-8/UTF-8" "nl_NL/ISO-8859-1"];
52 description = ''
53 List of locales that the system should support. The value
54 <literal>"all"</literal> means that all locales supported by
55 Glibc will be installed. A full list of supported locales
56 can be found at <link
57 xlink:href="https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED"/>.
58 '';
59 };
60
61 };
62
63 };
64
65
66 ###### implementation
67
68 config = {
69
70 environment.systemPackages =
71 # We increase the priority a little, so that plain glibc in systemPackages can't win.
72 optional (config.i18n.supportedLocales != []) (lib.setPrio (-1) config.i18n.glibcLocales);
73
74 environment.sessionVariables =
75 { LANG = config.i18n.defaultLocale;
76 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
77 } // config.i18n.extraLocaleSettings;
78
79 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) {
80 LOCALE_ARCHIVE = "${config.i18n.glibcLocales}/lib/locale/locale-archive";
81 };
82
83 # ‘/etc/locale.conf’ is used by systemd.
84 environment.etc."locale.conf".source = pkgs.writeText "locale.conf"
85 ''
86 LANG=${config.i18n.defaultLocale}
87 ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") config.i18n.extraLocaleSettings)}
88 '';
89
90 };
91}