at 23.11-pre 3.8 kB view raw
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.glibcLocales.override { 14 allLocales = any (x: x == "all") config.i18n.supportedLocales; 15 locales = config.i18n.supportedLocales; 16 }; 17 defaultText = literalExpression '' 18 pkgs.glibcLocales.override { 19 allLocales = any (x: x == "all") config.i18n.supportedLocales; 20 locales = config.i18n.supportedLocales; 21 } 22 ''; 23 example = literalExpression "pkgs.glibcLocales"; 24 description = lib.mdDoc '' 25 Customized pkg.glibcLocales package. 26 27 Changing this option can disable handling of i18n.defaultLocale 28 and supportedLocale. 29 ''; 30 }; 31 32 defaultLocale = mkOption { 33 type = types.str; 34 default = "en_US.UTF-8"; 35 example = "nl_NL.UTF-8"; 36 description = lib.mdDoc '' 37 The default locale. It determines the language for program 38 messages, the format for dates and times, sort order, and so on. 39 It also determines the character set, such as UTF-8. 40 ''; 41 }; 42 43 extraLocaleSettings = mkOption { 44 type = types.attrsOf types.str; 45 default = {}; 46 example = { LC_MESSAGES = "en_US.UTF-8"; LC_TIME = "de_DE.UTF-8"; }; 47 description = lib.mdDoc '' 48 A set of additional system-wide locale settings other than 49 `LANG` which can be configured with 50 {option}`i18n.defaultLocale`. 51 ''; 52 }; 53 54 supportedLocales = mkOption { 55 type = types.listOf types.str; 56 default = unique 57 (builtins.map (l: (replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8") ( 58 [ 59 "C.UTF-8" 60 "en_US.UTF-8" 61 config.i18n.defaultLocale 62 ] ++ (attrValues (filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings)) 63 )); 64 defaultText = literalExpression '' 65 unique 66 (builtins.map (l: (replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8") ( 67 [ 68 "C.UTF-8" 69 config.i18n.defaultLocale 70 ] ++ (attrValues (filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings)) 71 )) 72 ''; 73 example = ["en_US.UTF-8/UTF-8" "nl_NL.UTF-8/UTF-8" "nl_NL/ISO-8859-1"]; 74 description = lib.mdDoc '' 75 List of locales that the system should support. The value 76 `"all"` means that all locales supported by 77 Glibc will be installed. A full list of supported locales 78 can be found at <https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED>. 79 ''; 80 }; 81 82 }; 83 84 }; 85 86 87 ###### implementation 88 89 config = { 90 91 environment.systemPackages = 92 # We increase the priority a little, so that plain glibc in systemPackages can't win. 93 optional (config.i18n.supportedLocales != []) (lib.setPrio (-1) config.i18n.glibcLocales); 94 95 environment.sessionVariables = 96 { LANG = config.i18n.defaultLocale; 97 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; 98 } // config.i18n.extraLocaleSettings; 99 100 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) { 101 LOCALE_ARCHIVE = "${config.i18n.glibcLocales}/lib/locale/locale-archive"; 102 }; 103 104 # ‘/etc/locale.conf’ is used by systemd. 105 environment.etc."locale.conf".source = pkgs.writeText "locale.conf" 106 '' 107 LANG=${config.i18n.defaultLocale} 108 ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") config.i18n.extraLocaleSettings)} 109 ''; 110 111 }; 112}