{
  config,
  pkgs,
  lib,
  ...
}: let
  cfg = config.marleyos.programs.cheat;

  toYAML = (pkgs.formats.yaml {}).generate;
in {
  options.marleyos.programs.cheat.enable = lib.mkEnableOption "cheat";

  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      cheat
    ];

    xdg.configFile."cheat/conf.yml".source = toYAML "conf.yml" {
      colorize = true;
      formatter = "terminal256";
      pager = "less -FRX";

      cheatpaths = let
        cheatDir = "${config.xdg.configHome}/cheat/cheatsheets";
      in [
        {
          name = "community";
          path = "${cheatDir}/community";
          tags = ["community"];
          readonly = true;
        }
        {
          name = "personal";
          path = "${cheatDir}/personal";
          tags = ["personal"];
          readonly = false;
        }
      ];
    };
  };
}
