main
 1{
 2  pkgs,
 3  lib,
 4  config,
 5  ...
 6}: let
 7  cfg = config.programs.helix;
 8
 9  tomlFormat = pkgs.formats.toml {};
10in {
11  options.programs.helix = {
12    enable = lib.mkEnableOption "Helix text editor";
13    package = lib.mkPackageOption pkgs "helix" {
14      nullable = true;
15      example = "pkgs.steelix";
16    };
17    settings = lib.mkOption {
18      inherit (tomlFormat) type;
19      default = {};
20    };
21    languages = lib.mkOption {
22      type =
23        lib.types.coercedTo (lib.types.listOf tomlFormat.type)
24        (language: {inherit language;})
25        (lib.types.addCheck tomlFormat.type builtins.isAttrs);
26      default = {};
27    };
28  };
29
30  config = lib.mkIf cfg.enable {
31    packages = [cfg.package];
32
33    xdg.config.files."helix/config.toml" = {
34      generator = tomlFormat.generate "helix-config.toml";
35      value = cfg.settings;
36    };
37    xdg.config.files."helix/languages.toml" = {
38      generator = tomlFormat.generate "helix-languages.toml";
39      value = cfg.languages;
40    };
41  };
42}