{ lib, config, ... }:
{
  options = {
    custom.neovim.enable = lib.mkEnableOption "My neovim config";
  };
  config = lib.mkIf config.custom.neovim.enable {
    home = {
      sessionVariables = {
        EDITOR = "nvim";
      };
    };
    programs.nixvim = {
      enable = true;
      plugins = {
        dropbar.enable = true;
        lspconfig.enable = true;
        guess-indent.enable = true;
        gitsigns = {
          enable = true;
          settings = {
            sign_priority = 15;
          };
        };
        oil.enable = true;
        trouble.enable = true;
        web-devicons.enable = true;
        lualine.enable = true;
        mini-pairs.enable = true;
        snacks = {
          enable = true;
          settings = {
            picker = {
              ui_select = true;
              actions = {
                __raw = "require('trouble.sources.snacks').actions";
              };
              win.input.keys = {
                "<M-t>" = {
                  __unkeyed = "trouble_open";
                  mode = [ "n" "i" ];
                };
              };
            };
          };
        };
        mini-indentscope.enable = true;
        mini-surround.enable = true;
        ts-autotag.enable = true;
        blink-cmp = {
          enable = true;
          settings = {
            signature = {
              enabled = true;
            };
          };
        };
        treesitter = {
          enable = true;
          highlight.enable = true;
          indent.enable = true;
        };
        harpoon.enable = true;
      };
      keymaps = [
        {
          key = "<leader>o";
          action = "<cmd>Oil<CR>";
        }
        {
          key = "<leader>f";
          action = "<cmd>lua require('snacks').picker.files()<CR>";
        }
        {
          key = "<leader>l";
          action = "<cmd>lua require('snacks').picker.grep()<CR>";
        }
        {
          key = "<leader>h";
          action = "<cmd>lua require('snacks').picker.help()<CR>";
        }
        {
          key = "<leader>r";
          action = "<cmd>lua require('snacks').picker.resume()<CR>";
        }
        {
          key = "<leader>i";
          action = "<cmd>lua vim.lsp.buf.format()<CR>";
        }
        {
          key = "<leader>a";
          action = "<cmd>lua vim.lsp.buf.code_action()<CR>";
        }
        {
          key = "[d";
          action = "<cmd>lua vim.diagnostic.goto_prev({ float = true })<CR>";
        }
        {
          key = "]d";
          action = "<cmd>lua vim.diagnostic.goto_next({ float = true })<CR>";
        }
        {
          key = "<leader>q";
          action = "<cmd>Trouble diagnostics<CR>";
        }
        {
          key = "<leader>k";
          action = "<cmd>lua require('harpoon'):list():add()<CR>";
        }
        {
          key = "<M-q>";
          action = "<cmd>lua require('harpoon'):list():select(1)<CR>";
        }
        {
          key = "<M-w>";
          action = "<cmd>lua require('harpoon'):list():select(2)<CR>";
        }
        {
          key = "<M-e>";
          action = "<cmd>lua require('harpoon'):list():select(3)<CR>";
        }
        {
          key = "<M-r>";
          action = "<cmd>lua require('harpoon'):list():select(4)<CR>";
        }
        {
          key = "<leader>j";
          action = "<cmd>lua require('harpoon').ui:toggle_quick_menu(require('harpoon'):list())<CR>";
        }
        {
          key = "<leader>p";
          action = "<cmd>CopyRelativePath<CR>";
        }
        {
          key = "<leader>gb";
          action = "<cmd>Gitsigns blame<CR>";
        }
        {
          key = "<leader>gd";
          action = "<cmd>Gitsigns diffthis<CR>";
        }
        {
          key = "grr";
          action = "<cmd>Trouble lsp_references toggle focus=true<CR>";
        }
        {
          key = "gd";
          action = "<cmd>Trouble lsp_definitions toggle focus=true<CR>";
        }
        {
          key = "gi";
          action = "<cmd>Trouble lsp_implementations toggle focus=true<CR>";
        }
        {
          key = "gy";
          action = "<cmd>Trouble lsp_type_definitions toggle focus=true<CR>";
        }
      ];
      globals.mapleader = " ";
      opts = {
        number = true;
        relativenumber = true;
        ignorecase = true;
        smartcase = true;
        swapfile = false;
        exrc = true;
      };
      colorschemes.catppuccin = {
        enable = true;
        settings = {
          custom_highlights = {
            __raw = ''
              function(colors)
                return {
                  LineNr = { fg = colors.subtext0 },
                }
              end
            '';
          };
        };
      };
      clipboard.register = "unnamedplus";
      userCommands = {
        CopyRelativePath = {
          command = "call setreg('+', expand('%'))";
        };
      };
      lsp.servers = {
        basedpyright.enable = true;
        gopls.enable = true;
        nil_ls.enable = true;
        rust_analyzer.enable = true;
        html.enable = true;
        jsonls.enable = true;
        yamlls.enable = true;
        cssls.enable = true;
        tailwindcss.enable = true;
        vtsls.enable = true;
        lua_ls.enable = true;
      };
    };
  };
}
