{
  pkgs,
  lib,
  config,
  inputs,
  ...
}: let
  d2-vim = pkgs.vimUtils.buildVimPlugin {
    pname = "d2-vim";
    version = "0.1.0";
    src = pkgs.fetchFromGitHub {
      owner = "terrastruct";
      repo = "d2-vim";
      rev = "cb3eb7fcb1a2d45c4304bf2e91077d787b724a39";
      hash = "sha256-HmDQfOIoSV93wqRe7O4FPuHEmAxwoP1+Ut+sKhB62jA=";
      fetchSubmodules = true;
    };
  };
in {
  options.mods.nvim.enable =
    lib.mkEnableOption "enables nvim";

  imports = [
    inputs.nvf.homeManagerModules.default
    ./obsidian.nix
  ];

  config = lib.mkIf config.mods.nvim.enable {
    home.packages = [pkgs.d2];
    programs.nvf = {
      enable = true;
      settings = {
        vim = {
          viAlias = true;
          vimAlias = true;
          lsp = {
            enable = true;
            formatOnSave = true;
          };

          keymaps = [
            {
              key = "<leader>w";
              mode = ["n"];
              action = ":w<CR>";
              silent = true;
              desc = "Save file";
            }
            {
              key = "<leader>q";
              mode = ["n"];
              action = ":q<CR>";
              silent = false;
              desc = "Quit";
            }
            {
              key = "gd";
              mode = "n";
              silent = true;
              action = "<cmd>lua vim.lsp.buf.definition()<CR>";
              desc = "Go to Definition";
            }
          ];

          languages = {
            enableFormat = true;
            # enableTreesitter = true;
            enableExtraDiagnostics = true;

            nix.enable = true;
            markdown.enable = true;
            bash.enable = true;
            rust.enable = true;
            rust.extensions.crates-nvim.enable = true;

            python = {
              enable = true;
              format.type = ["ruff" "black"];
            };

            clang = {
              enable = true;
              cHeader = true;
            };
          };

          startPlugins = [d2-vim];

          treesitter = {
            enable = true;
            context.enable = true;
          };

          statusline.lualine.enable = true;
          telescope.enable = true;
          autocomplete.nvim-cmp.enable = true;
          autopairs.nvim-autopairs.enable = true;
          tabline.nvimBufferline.enable = true;
          # treesitter.context.enable = true;
          comments.comment-nvim.enable = true;
          notes.todo-comments.enable = true;

          clipboard = {
            enable = true;
            providers.xclip.enable = true;
          };

          mini = {
            ai.enable = true;
            comment.enable = true;
            surround.enable = true;
          };

          options = {
            tabstop = 2;
            shiftwidth = 0;
            conceallevel = 2;
          };

          spellcheck = {enable = true;};

          binds = {
            whichKey.enable = true;
            cheatsheet.enable = true;
          };

          git = {
            enable = true;
            gitsigns.enable = true;
            gitsigns.codeActions.enable =
              false; # throws an annoying debug message
          };

          utility = {
            diffview-nvim.enable = true;
            surround.enable = true;
            undotree.enable = true;

            motion = {
              hop.enable = true;
              leap.enable = true;
            };
          };

          visuals = {
            nvim-web-devicons.enable = true;
            nvim-cursorline.enable = true;
            cinnamon-nvim.enable = true;
            fidget-nvim.enable = true;

            highlight-undo.enable = true;
            indent-blankline.enable = true;
          };

          ui = {
            borders.enable = true;
            noice.enable = true;
            colorizer.enable = true;
            illuminate.enable = true;
            smartcolumn.enable = true;
            fastaction.enable = true;
          };
        };
      };
    };
  };
}
