at v206 3.2 kB view raw
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 }; 78 79 }; 80 81 82 ###### implementation 83 84 config = { 85 86 i18n.consoleKeyMap = with config.services.xserver; 87 mkIf config.i18n.consoleUseXkbConfig 88 (pkgs.runCommand "xkb-console-keymap" { preferLocalBuild = true; } '' 89 '${pkgs.ckbcomp}/bin/ckbcomp' -model '${xkbModel}' -layout '${layout}' \ 90 -option '${xkbOptions}' -variant '${xkbVariant}' > "$out" 91 ''); 92 93 environment.systemPackages = 94 optional (config.i18n.supportedLocales != []) glibcLocales; 95 96 environment.sessionVariables = 97 { LANG = config.i18n.defaultLocale; 98 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; 99 }; 100 101 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) { 102 LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; 103 }; 104 105 # ‘/etc/locale.conf’ is used by systemd. 106 environment.etc = singleton 107 { target = "locale.conf"; 108 source = pkgs.writeText "locale.conf" 109 '' 110 LANG=${config.i18n.defaultLocale} 111 ''; 112 }; 113 114 }; 115}