{...}: let
  global = import ../global-var.nix;
in {
  home-manager.users.${global.username} = {pkgs, ...}: {
    programs.neovim = {
      enable = true;
      defaultEditor = true;

      extraLuaConfig = ''

          vim.cmd('syntax on')

          vim.wo.number = true
          vim.wo.relativenumber = true

          vim.bo.autoindent = true

          vim.bo.tabstop = 4

          vim.o.ignorecase = true

          vim.o.ttyfast = true

          vim.o.termguicolors = true

          vim.bo.expandtab = true

          vim.o.cmdheight = 0
          vim.cmd.colorscheme "catppuccin"

          require('nvim-tree').setup {
            tab = { sync = { open = true, close = true, ignore = {} } },
          }

          require('gitsigns').setup()

          require('Comment').setup()

          require('lualine').setup {
            options = {
              theme = "catppuccin",
              disabled_filetypes = {
                statusline = {"NvimTree"},
              },
            },
          }

          require'colorizer'.setup {
            filetypes = {
              '*',
            },
          }

          vim.api.nvim_create_autocmd("FileType", {
            pattern = "nix",
            callback = function()
              vim.bo.expandtab = true
              vim.bo.shiftwidth = 2
              vim.bo.tabstop = 2
              vim.bo.softtabstop = 2
            end,
          })

          vim.api.nvim_create_autocmd('TextYankPost', {
            desc = 'Highlight when yanking (copying) text',
            group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
            callback = function()
              vim.highlight.on_yank()
            end,
          })

          require("nvim-autopairs").setup {}
          require("ibl").setup {}

          local function open_nvim_tree()
            -- open the tree
            require("nvim-tree.api").tree.open()
          end

          -- vim.api.nvim_create_autocmd("VimEnter", { callback = open_nvim_tree })
          -- vim.api.nvim_create_autocmd("TabEnter", { callback = open_nvim_tree })

          vim.api.nvim_set_keymap('n', '<F2>', ':NvimTreeToggle<CR>', { noremap = true, silent = true })

          if vim.g.neovide then
            vim.o.guifont = "iosevka Nerd Font:h12"
            vim.g.neovide_transparency = 0.9
          end

        -- Your existing Lua configuration here

        -- LSP setup
        local lspconfig = require('lspconfig')
        local capabilities = require('cmp_nvim_lsp').default_capabilities()

        -- Setup language servers
        lspconfig.pyright.setup{capabilities = capabilities}
        lspconfig.tsserver.setup{capabilities = capabilities}
        lspconfig.rust_analyzer.setup{capabilities = capabilities}
        lspconfig.nil_ls.setup{capabilities = capabilities}
        lspconfig.clangd.setup{capabilities = capabilities}

        -- Global mappings
        vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
        vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
        vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
        vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)

        -- Use LspAttach autocommand to only map the following keys
        -- after the language server attaches to the current buffer
        vim.api.nvim_create_autocmd('LspAttach', {
          group = vim.api.nvim_create_augroup('UserLspConfig', {}),
          callback = function(ev)
            local opts = { buffer = ev.buf }
            vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
            vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
            vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
            vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
            vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
            vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
            vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
            vim.keymap.set('n', '<space>wl', function()
              print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
            end, opts)
            vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
            vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
            vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
            vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
            vim.keymap.set('n', '<space>f', function()
              vim.lsp.buf.format { async = true }
            end, opts)
          end,
        })

        -- Setup nvim-cmp
        local cmp = require'cmp'

        cmp.setup({
          snippet = {
            expand = function(args)
              require('luasnip').lsp_expand(args.body)
            end,
          },
          mapping = cmp.mapping.preset.insert({
            ['<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 }),
          }),
          sources = cmp.config.sources({
            { name = 'nvim_lsp' },
            { name = 'luasnip' },
          }, {
            { name = 'buffer' },
          })
        })
      '';

      plugins = with pkgs.vimPlugins; [
        gitsigns-nvim
        nvim-lspconfig
        nvim-cmp
        cmp-nvim-lsp
        cmp-buffer
        cmp-path
        cmp-cmdline
        luasnip
        cmp_luasnip
        catppuccin-nvim
        nvim-tree-lua
        nvim-web-devicons
        barbar-nvim
        lualine-nvim
        nvim-colorizer-lua
        nvim-autopairs
        comment-nvim
        indent-blankline-nvim
        nvim-treesitter.withAllGrammars
      ];
    };

    home.packages = with pkgs; [
      pyright
      nodePackages.typescript-language-server
      rust-analyzer
      nil
      cargo
      clang-tools
    ];
  };
}
