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 consolePackages = mkOption {
45 type = types.listOf types.package;
46 default = with pkgs.kbdKeymaps; [ dvp neo ];
47 description = ''
48 List of additional packages that provide console fonts, keymaps and
49 other resources.
50 '';
51 };
52
53 consoleFont = mkOption {
54 type = types.str;
55 default = "Lat2-Terminus16";
56 example = "LatArCyrHeb-16";
57 description = ''
58 The font used for the virtual consoles. Leave empty to use
59 whatever the <command>setfont</command> program considers the
60 default font.
61 '';
62 };
63
64 consoleUseXkbConfig = mkOption {
65 type = types.bool;
66 default = false;
67 description = ''
68 If set, configure the console keymap from the xserver keyboard
69 settings.
70 '';
71 };
72
73 consoleKeyMap = mkOption {
74 type = mkOptionType {
75 name = "string or path";
76 check = t: (isString t || types.path.check t);
77 };
78
79 default = "us";
80 example = "fr";
81 description = ''
82 The keyboard mapping table for the virtual consoles.
83 '';
84 };
85
86 consoleColors = mkOption {
87 type = types.listOf types.str;
88 default = [];
89 example = [
90 "002b36" "dc322f" "859900" "b58900"
91 "268bd2" "d33682" "2aa198" "eee8d5"
92 "002b36" "cb4b16" "586e75" "657b83"
93 "839496" "6c71c4" "93a1a1" "fdf6e3"
94 ];
95 description = ''
96 The 16 colors palette used by the virtual consoles.
97 Leave empty to use the default colors.
98 Colors must be in hexadecimal format and listed in
99 order from color 0 to color 15.
100 '';
101 };
102
103 };
104
105 };
106
107
108 ###### implementation
109
110 config = {
111
112 i18n.consoleKeyMap = with config.services.xserver;
113 mkIf config.i18n.consoleUseXkbConfig
114 (pkgs.runCommand "xkb-console-keymap" { preferLocalBuild = true; } ''
115 '${pkgs.ckbcomp}/bin/ckbcomp' -model '${xkbModel}' -layout '${layout}' \
116 -option '${xkbOptions}' -variant '${xkbVariant}' > "$out"
117 '');
118
119 environment.systemPackages =
120 optional (config.i18n.supportedLocales != []) glibcLocales;
121
122 environment.sessionVariables =
123 { LANG = config.i18n.defaultLocale;
124 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
125 };
126
127 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) {
128 LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive";
129 };
130
131 # ‘/etc/locale.conf’ is used by systemd.
132 environment.etc = singleton
133 { target = "locale.conf";
134 source = pkgs.writeText "locale.conf"
135 ''
136 LANG=${config.i18n.defaultLocale}
137 '';
138 };
139
140 };
141}