1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 glibcLocales = pkgs.glibcLocales.override {
8 allLocales = any (x: x == "all") config.i18n.supportedLocales;
9 locales = config.i18n.supportedLocales;
10 };
11
12in
13
14{
15 ###### interface
16
17 options = {
18
19 i18n = {
20 defaultLocale = mkOption {
21 type = types.str;
22 default = "en_US.UTF-8";
23 example = "nl_NL.UTF-8";
24 description = ''
25 The default locale. It determines the language for program
26 messages, the format for dates and times, sort order, and so on.
27 It also determines the character set, such as UTF-8.
28 '';
29 };
30
31 supportedLocales = mkOption {
32 type = types.listOf types.str;
33 default = ["all"];
34 example = ["en_US.UTF-8/UTF-8" "nl_NL.UTF-8/UTF-8" "nl_NL/ISO-8859-1"];
35 description = ''
36 List of locales that the system should support. The value
37 <literal>"all"</literal> means that all locales supported by
38 Glibc will be installed. A full list of supported locales
39 can be found at <link
40 xlink:href="http://sourceware.org/cgi-bin/cvsweb.cgi/libc/localedata/SUPPORTED?cvsroot=glibc"/>.
41 '';
42 };
43
44 consoleFont = mkOption {
45 type = types.str;
46 default = "Lat2-Terminus16";
47 example = "LatArCyrHeb-16";
48 description = ''
49 The font used for the virtual consoles. Leave empty to use
50 whatever the <command>setfont</command> program considers the
51 default font.
52 '';
53 };
54
55 consoleUseXkbConfig = mkOption {
56 type = types.bool;
57 default = false;
58 description = ''
59 If set, configure the console keymap from the xserver keyboard
60 settings.
61 '';
62 };
63
64 consoleKeyMap = mkOption {
65 type = mkOptionType {
66 name = "string or path";
67 check = t: (isString t || types.path.check t);
68 };
69
70 default = "us";
71 example = "fr";
72 description = ''
73 The keyboard mapping table for the virtual consoles.
74 '';
75 };
76
77 consoleColors = mkOption {
78 type = types.listOf types.str;
79 default = [];
80 example = [
81 "002b36" "dc322f" "859900" "b58900"
82 "268bd2" "d33682" "2aa198" "eee8d5"
83 "002b36" "cb4b16" "586e75" "657b83"
84 "839496" "6c71c4" "93a1a1" "fdf6e3"
85 ];
86 description = ''
87 The 16 colors palette used by the virtual consoles.
88 Leave empty to use the default colors.
89 Colors must be in hexadecimal format and listed in
90 order from color 0 to color 15.
91 '';
92 };
93
94 };
95
96 };
97
98
99 ###### implementation
100
101 config = {
102
103 i18n.consoleKeyMap = with config.services.xserver;
104 mkIf config.i18n.consoleUseXkbConfig
105 (pkgs.runCommand "xkb-console-keymap" { preferLocalBuild = true; } ''
106 '${pkgs.ckbcomp}/bin/ckbcomp' -model '${xkbModel}' -layout '${layout}' \
107 -option '${xkbOptions}' -variant '${xkbVariant}' > "$out"
108 '');
109
110 environment.systemPackages =
111 optional (config.i18n.supportedLocales != []) glibcLocales;
112
113 environment.sessionVariables =
114 { LANG = config.i18n.defaultLocale;
115 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
116 };
117
118 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) {
119 LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";
120 };
121
122 # ‘/etc/locale.conf’ is used by systemd.
123 environment.etc = singleton
124 { target = "locale.conf";
125 source = pkgs.writeText "locale.conf"
126 ''
127 LANG=${config.i18n.defaultLocale}
128 '';
129 };
130
131 };
132}