some refactoring and modularizing locale

This commit is contained in:
cnst
2024-10-23 20:11:01 +02:00
parent 86046c6414
commit b7784f9b15
58 changed files with 256 additions and 165 deletions

View File

@@ -0,0 +1,64 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkOption mkDefault;
cfg = config.nixos.system.locale;
defaultCategories = [
"LC_ADDRESS"
"LC_IDENTIFICATION"
"LC_MEASUREMENT"
"LC_MONETARY"
"LC_NAME"
"LC_NUMERIC"
"LC_PAPER"
"LC_TELEPHONE"
"LC_TIME"
];
in {
options = {
nixos.system.locale = {
enable = mkOption {
type = lib.types.bool;
default = true;
description = "Enable locale configuration.";
};
timeZone = mkOption {
type = lib.types.str;
default = null;
description = "The system time zone (e.g., \"Europe/Stockholm\").";
};
defaultLocale = mkOption {
type = lib.types.str;
default = null;
description = "The default locale for the system (e.g., \"en_US.UTF-8\").";
};
extraLocale = mkOption {
type = lib.types.str;
default = null;
description = ''
The locale to use for specific LC_* categories.
If set, it will override the categories specified in `locale.categories`.
Example: "sv_SE.UTF-8".
'';
};
categories = mkOption {
type = lib.types.listOf lib.types.str;
default = defaultCategories;
description = ''
List of LC_* categories to override with `locale.extraLocale`.
Defaults to common locale categories.
'';
};
};
};
config = mkIf cfg.enable {
time.timeZone = mkDefault cfg.timeZone;
i18n.defaultLocale = mkDefault cfg.defaultLocale;
i18n.extraLocaleSettings = mkIf (cfg.extraLocale != null) (
lib.foldl' (attrs: lc: attrs // {"${lc}" = cfg.extraLocale;}) {} cfg.categories
);
};
}