summaryrefslogtreecommitdiff
path: root/modules/locales.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/locales.nix')
-rw-r--r--modules/locales.nix60
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/locales.nix b/modules/locales.nix
new file mode 100644
index 0000000..73627f8
--- /dev/null
+++ b/modules/locales.nix
@@ -0,0 +1,60 @@
+{ lib, config, pkgs, ... }:
+
+let localeMap = {
+ c = "C.UTF-8";
+ us = "en_US.UTF-8";
+ it = "it_IT.UTF-8";
+ jp = "ja_JP.UTF-8";
+ };
+
+ dictOverlay = with pkgs.aspellDicts; {
+ us = en;
+ };
+ dicts = pkgs.aspellDicts // dictOverlay;
+
+ getSafe' = with builtins;
+ (key: attrs: if hasAttr key attrs then [(getAttr key attrs)] else []);
+
+ inherit (lib) types;
+ cfg = config.this.locales;
+in
+{
+ options = {
+ this.locales = {
+ default = lib.mkOption {
+ type = types.str;
+ default = "us";
+ };
+ extra = lib.mkOption {
+ type = types.listOf types.str;
+ default = [];
+ };
+ dictionaries = {
+ enable = lib.mkEnableOption "dictionaries";
+ extra = lib.mkOption {
+ type = types.listOf types.str;
+ default = [];
+ };
+ };
+
+ all = lib.mkOption {
+ description = "READ-ONLY!";
+ default = ["c" cfg.default] ++ cfg.extra;
+ };
+ };
+ };
+
+ config = {
+ i18n = {
+ defaultLocale = localeMap.${cfg.default};
+ supportedLocales =
+ builtins.map (l: localeMap.${l} + "/UTF-8") cfg.all;
+ };
+
+ environment.systemPackages =
+ (lib.optionals cfg.dictionaries.enable
+ (builtins.concatMap (l: getSafe' l dicts)
+ cfg.all))
+ ++ builtins.map (d: pkgs.aspellDicts.${d}) cfg.dictionaries.extra;
+ };
+}