summaryrefslogtreecommitdiff
path: root/modules/locales.nix
blob: 73627f87cfa54e24a53645463e0cbd02dfec5372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
  };
}