{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.programs.nixvim;
  plugin = cfg.plugins.telescope;

  inherit (lib) mkDefault optionals;
in
{
  config = {
    programs.nixvim = {
      plugins.telescope = {
        enable = mkDefault true;
        settings = {
          defaults = {
            vimgrep_arguments = [
              "rg"
              "--color=never"
              "--no-heading"
              "--with-filename"
              "--line-number"
              "--column"
              "--smart-case"
              "--hidden"
            ];
            file_ignore_patterns = [
              "^.git/"
              "^.direnv/"
              "^.cache/"
              "^node_modules/"
            ];
          };
          pickers = {
            find_files = {
              hidden = true;
            };
          };
        };
        extensions = {
          file-browser.enable = mkDefault true;
          fzf-native.enable = mkDefault true;
          live-grep-args.enable = mkDefault true;
          manix.enable = mkDefault true;
        };
        keymaps = mkDefault {
          "<C-e>" = "file_browser";
          "<C-p>" = "git_files";
          "<leader>bl" = "buffers";
          "<leader>fd" = "diagnostics";
          "<leader>ff" = "find_files";
          "<leader>fg" = "live_grep";
          "<leader>fh" = "help_tags";
          "<leader>fm" = "man_pages";
          "<leader>fn" = "manix";
          "<leader>fo" = "oldfiles";
          "<space>fb" = "file_browser";
        };
      };
      keymaps = optionals plugin.enable [
        {
          key = "<C-f>";
          action = ":lua require('telescope').extensions.live_grep_args.live_grep_args()<CR>";
          mode = "n";
        }
      ];
    };

    home.packages = optionals plugin.enable [
      pkgs.ripgrep # for "live_grep"
    ];
  };
}
