at 24.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 = '' 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 = '' 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 = '' 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 "en_US.UTF-8" 70 config.i18n.defaultLocale 71 ] ++ (attrValues (filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings)) 72 )) 73 ''; 74 example = ["en_US.UTF-8/UTF-8" "nl_NL.UTF-8/UTF-8" "nl_NL/ISO-8859-1"]; 75 description = '' 76 List of locales that the system should support. The value 77 `"all"` means that all locales supported by 78 Glibc will be installed. A full list of supported locales 79 can be found at <https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED>. 80 ''; 81 }; 82 83 }; 84 85 }; 86 87 88 ###### implementation 89 90 config = { 91 92 environment.systemPackages = 93 # We increase the priority a little, so that plain glibc in systemPackages can't win. 94 optional (config.i18n.supportedLocales != []) (lib.setPrio (-1) config.i18n.glibcLocales); 95 96 environment.sessionVariables = 97 { LANG = config.i18n.defaultLocale; 98 LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; 99 } // config.i18n.extraLocaleSettings; 100 101 systemd.globalEnvironment = mkIf (config.i18n.supportedLocales != []) { 102 LOCALE_ARCHIVE = "${config.i18n.glibcLocales}/lib/locale/locale-archive"; 103 }; 104 105 # ‘/etc/locale.conf’ is used by systemd. 106 environment.etc."locale.conf".source = pkgs.writeText "locale.conf" 107 '' 108 LANG=${config.i18n.defaultLocale} 109 ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") config.i18n.extraLocaleSettings)} 110 ''; 111 112 }; 113}