fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.6 KiB63 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.alacritty;
7  yamlFormat = pkgs.formats.yaml { };
8in {
9  options = {
10    programs.alacritty = {
11      enable = mkEnableOption "Alacritty";
12
13      package = mkOption {
14        type = types.package;
15        default = pkgs.alacritty;
16        defaultText = literalExpression "pkgs.alacritty";
17        description = "The Alacritty package to install.";
18      };
19
20      settings = mkOption {
21        type = yamlFormat.type;
22        default = { };
23        example = literalExpression ''
24          {
25            window.dimensions = {
26              lines = 3;
27              columns = 200;
28            };
29            key_bindings = [
30              {
31                key = "K";
32                mods = "Control";
33                chars = "\\x0c";
34              }
35            ];
36          }
37        '';
38        description = ''
39          Configuration written to
40          {file}`$XDG_CONFIG_HOME/alacritty/alacritty.yml`. See
41          <https://github.com/alacritty/alacritty/blob/master/alacritty.yml>
42          for the default configuration.
43        '';
44      };
45    };
46  };
47
48  config = mkMerge [
49    (mkIf cfg.enable {
50      home.packages = [ cfg.package ];
51
52      xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) {
53        # TODO: Replace by the generate function but need to figure out how to
54        # handle the escaping first.
55        #
56        # source = yamlFormat.generate "alacritty.yml" cfg.settings;
57
58        text =
59          replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings);
60      };
61    })
62  ];
63}