{ pkgs, ... }:
{
  programs.nixvim = {
    diagnostic.settings = {
      virtual_text = true;
    };

    plugins = {
      lsp = {
        enable = true;
        inlayHints = true;

        servers = {
          bashls.enable = true;
          qmlls.enable = true;
          qmlls.package = null;
          qmlls.cmd = [
            "qmlls"
            "-E"
          ];
          clangd.package = null;
          clangd.enable = true;
          clangd.cmd = [
            "clangd"
            "--background-index"
            "--query-driver=${pkgs.clang}/bin/clang++"
            "--query-driver=${pkgs.clang}/bin/clang"
          ];
          nixd.enable = true;
        };
      };

      conform-nvim = {
        enable = true;
        settings = {
          format_on_save = {
            lspFormat = "fallback";
            timeoutMs = 500;
          };

          formatters_by_ft = {
            lua = [ "stylua" ];
            nix = [ "nixfmt" ];
            python = [ "ruff_format" ];
            javascript = [ "prettier" ];
            typescript = [ "prettier" ];
            svelte = [ "prettier" ];
            css = [ "prettier" ];
            json = [ "prettier" ];
            html = [ "prettier" ];
          };
        };
      };

      cmp = {
        enable = true;
        autoEnableSources = true;

        settings = {
          sources = [
            { name = "nvim_lsp"; }
            { name = "path"; }
            { name = "buffer"; }
          ];

          mapping = {
            "<C-b>" = "cmp.mapping.scroll_docs(-4)";
            "<C-f>" = "cmp.mapping.scroll_docs(4)";
            "<C-Space>" = "cmp.mapping.complete()";
            "<C-e>" = "cmp.mapping.abort()";
            "<CR>" = "cmp.mapping.confirm({ select = true })";
            "<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
            "<S-Tab>" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})";
          };

          window.completion.border = "rounded";
          window.documentation.border = "rounded";
        };
      };
    };
  };
}
