{ 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 { type = types.listOf types.str; default = []; }; }; }; config = { this.locales.all = ["c" cfg.default] ++ cfg.extra; 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; }; }