summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoron Behar <doron.behar@gmail.com>2026-01-18 20:08:08 +0000
committerGitHub <noreply@github.com>2026-01-18 20:08:08 +0000
commitb38848f4e234f6270ad0e386483cb5f81240656f (patch)
tree84e33c6f8435f7237b0de8283a6f8ddf1668e367
parentc5a6500fb242b4ee59c369c3b2dcf9d74bc1a6e2 (diff)
parent26813ab5180a6d9d22a5db586f39bdf9ee22bd51 (diff)
nixos/i18n: handle C locale better (#460010)
-rw-r--r--nixos/modules/config/i18n.nix32
-rw-r--r--nixos/tests/i18n.nix28
2 files changed, 46 insertions, 14 deletions
diff --git a/nixos/modules/config/i18n.nix b/nixos/modules/config/i18n.nix
index e9955859bffd..aa8f06d1c7f2 100644
--- a/nixos/modules/config/i18n.nix
+++ b/nixos/modules/config/i18n.nix
@@ -7,19 +7,22 @@
let
sanitizeUTF8Capitalization =
lang: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] lang);
- aggregatedLocales = [
- "${config.i18n.defaultLocale}/${config.i18n.defaultCharset}"
- ]
- ++ lib.pipe config.i18n.extraLocaleSettings [
- # See description of extraLocaleSettings for why is this ignored here.
- (x: lib.removeAttrs x [ "LANGUAGE" ])
- (lib.mapAttrs (n: v: (sanitizeUTF8Capitalization v)))
- (lib.mapAttrsToList (LCRole: lang: lang + "/" + (config.i18n.localeCharsets.${LCRole} or "UTF-8")))
- ]
- ++ (map sanitizeUTF8Capitalization (
- lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales
- ))
- ++ (lib.optional (builtins.isString config.i18n.extraLocales) config.i18n.extraLocales);
+ aggregatedLocales =
+ lib.optionals (config.i18n.defaultLocale != "C") [
+ "${config.i18n.defaultLocale}/${config.i18n.defaultCharset}"
+ ]
+ ++ lib.pipe config.i18n.extraLocaleSettings [
+ # See description of extraLocaleSettings for why is this ignored here.
+ (x: lib.removeAttrs x [ "LANGUAGE" ])
+ (lib.mapAttrs (n: v: (sanitizeUTF8Capitalization v)))
+ # C locales are always installed
+ (lib.filterAttrs (n: v: v != "C"))
+ (lib.mapAttrsToList (LCRole: lang: lang + "/" + (config.i18n.localeCharsets.${LCRole} or "UTF-8")))
+ ]
+ ++ (map sanitizeUTF8Capitalization (
+ lib.optionals (builtins.isList config.i18n.extraLocales) config.i18n.extraLocales
+ ))
+ ++ (lib.optional (builtins.isString config.i18n.extraLocales) config.i18n.extraLocales);
in
{
###### interface
@@ -111,6 +114,9 @@ in
description = ''
Per each {option}`i18n.extraLocaleSettings`, choose the character set
to use for it. Essentially defaults to UTF-8 for all of them.
+
+ Note that for a locale category that uses the `C` locale, setting a
+ character set to it via this setting is ignored.
'';
};
diff --git a/nixos/tests/i18n.nix b/nixos/tests/i18n.nix
index a0493b7c62f5..77f0cc579d5d 100644
--- a/nixos/tests/i18n.nix
+++ b/nixos/tests/i18n.nix
@@ -38,6 +38,32 @@
};
};
};
+ Csimple = {
+ i18n = {
+ defaultLocale = "C";
+ };
+ };
+ CnonDefault = {
+ i18n = {
+ defaultLocale = "en_US.UTF-8";
+ extraLocaleSettings = {
+ LC_COLLATE = "C";
+ LC_MESSAGES = "C";
+ LC_TIME = "C";
+ };
+ };
+ };
};
- testScript = { nodes, ... }: "";
+ testScript =
+ { nodes, ... }:
+ lib.pipe nodes [
+ builtins.attrNames
+ (map (node: ''
+ ${node}.copy_from_vm(
+ ${node}.succeed("readlink -f /etc/locale.conf").strip(),
+ "${node}"
+ )
+ ''))
+ (lib.concatStringsSep "\n")
+ ];
}