nixos/i18n: add extraLocales option (#356477)

This commit is contained in:
Doron Behar
2025-04-30 12:06:27 +03:00
committed by GitHub
3 changed files with 45 additions and 21 deletions

View File

@@ -360,6 +360,11 @@
## Other Notable Changes {#sec-nixpkgs-release-25.05-notable-changes} ## Other Notable Changes {#sec-nixpkgs-release-25.05-notable-changes}
- `i18n` module improvements:
- `i18n.extraLocales` should now be the preferred way to install additional locales.
- `i18n.supportedLocales` is now considered an implementation detail and will be hidden from the documentation. But the option will still continue to work.
- `i18n.supportedLocales` will now trigger a warning when it omits any locale set in `i18n.defaultLocale`, `i18n.extraLocales` or `i18n.extraLocaleSettings`.
- `titaniumenv`, `titanium`, and `titanium-alloy` have been removed due to lack of maintenance in Nixpkgs []{#sec-nixpkgs-release-25.05-incompatibilities-titanium-removed}. - `titaniumenv`, `titanium`, and `titanium-alloy` have been removed due to lack of maintenance in Nixpkgs []{#sec-nixpkgs-release-25.05-incompatibilities-titanium-removed}.
- androidenv has been improved: - androidenv has been improved:

View File

@@ -1,6 +1,6 @@
# Minimal {#sec-profile-minimal} # Minimal {#sec-profile-minimal}
This profile defines a small NixOS configuration. It does not contain any This profile defines a small NixOS configuration. It does not contain any
graphical stuff. It's a very short file that sets [](#opt-i18n.supportedLocales) graphical stuff. It's a very short file that sets the supported locales
to only support the user-selected locale, and to only support the user-selected locale, and
[disables packages' documentation](#opt-documentation.enable). [disables packages' documentation](#opt-documentation.enable).

View File

@@ -4,6 +4,16 @@
pkgs, pkgs,
... ...
}: }:
let
aggregatedLocales =
builtins.map
(l: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8")
(
[ config.i18n.defaultLocale ]
++ config.i18n.extraLocales
++ (lib.attrValues (lib.filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings))
);
in
{ {
###### interface ###### interface
@@ -42,6 +52,17 @@
''; '';
}; };
extraLocales = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "nl_NL.UTF-8" ];
description = ''
Additional locales that the system should support, besides the ones
configured with {option}`i18n.defaultLocale` and
{option}`i18n.extraLocaleSettings`.
'';
};
extraLocaleSettings = lib.mkOption { extraLocaleSettings = lib.mkOption {
type = lib.types.attrsOf lib.types.str; type = lib.types.attrsOf lib.types.str;
default = { }; default = { };
@@ -58,28 +79,14 @@
supportedLocales = lib.mkOption { supportedLocales = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
visible = false;
default = lib.unique ( default = lib.unique (
builtins.map
(l: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8")
(
[ [
"C.UTF-8" "C.UTF-8/UTF-8"
"en_US.UTF-8" "en_US.UTF-8/UTF-8"
config.i18n.defaultLocale
] ]
++ (lib.attrValues (lib.filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings)) ++ aggregatedLocales
)
); );
defaultText = lib.literalExpression ''
lib.unique
(builtins.map (l: (lib.replaceStrings [ "utf8" "utf-8" "UTF8" ] [ "UTF-8" "UTF-8" "UTF-8" ] l) + "/UTF-8") (
[
"C.UTF-8"
"en_US.UTF-8"
config.i18n.defaultLocale
] ++ (lib.attrValues (lib.filterAttrs (n: v: n != "LANGUAGE") config.i18n.extraLocaleSettings))
))
'';
example = [ example = [
"en_US.UTF-8/UTF-8" "en_US.UTF-8/UTF-8"
"nl_NL.UTF-8/UTF-8" "nl_NL.UTF-8/UTF-8"
@@ -100,6 +107,18 @@
###### implementation ###### implementation
config = { config = {
warnings =
lib.optional ((lib.subtractLists config.i18n.supportedLocales aggregatedLocales) != [ ])
''
`i18n.supportedLocales` is deprecated in favor of `i18n.extraLocales`,
and it seems you are using `i18n.supportedLocales` and forgot to
include some locales specified in `i18n.defaultLocale`,
`i18n.extraLocales` or `i18n.extraLocaleSettings`.
If you're trying to install additional locales not specified in
`i18n.defaultLocale` or `i18n.extraLocaleSettings`, consider adding
only those locales to `i18n.extraLocales`.
'';
environment.systemPackages = environment.systemPackages =
# We increase the priority a little, so that plain glibc in systemPackages can't win. # We increase the priority a little, so that plain glibc in systemPackages can't win.