{ inputs, pkgs, lib, theme, ... }: {
  imports = [
    ./alpha.nix
    ./keymaps.nix
    inputs.nixvim.homeManagerModules.nixvim
  ] ++ lib.optional (builtins.isString theme) ../../../../../stylix/themes/${theme}/home-manager/nixvim.nix;
  
  # https://github.com/nix-community/nixvim
  home.packages = with pkgs; [
    # Linters 
    yamllint
    hadolint 
    nixfmt-rfc-style
    vale
    clj-kondo
  ];

  # Docs:
  # https://nix-community.github.io/nixvim/
  programs.nixvim = {
    enable = true;
    viAlias = true;
    vimAlias = true;
    vimdiffAlias = true;

    globals.mapleader = " ";
    globals.maplocalleader = " ";

    opts = {
      number = true;
      wrap = false;
      cursorline = true;
      cursorcolumn = true;
      shiftwidth = 2;
      breakindent = true;
      colorcolumn = "100";
      showmode = false;
      termguicolors = true;
    };

    extraConfigLuaPost = ''
      vim.opt.shell = '/run/current-system/sw/bin/fish'
    '';

    plugins = {
      web-devicons.enable = true;
    # Git related
      # Gutter information for git modifications
      gitsigns.enable = true;
      # git plugin for vim
      fugitive.enable = true;
  
    # pretty stuff
      # Fancify markdown et al 
      render-markdown.enable = true;
      # Rainbow matching {} [] () 's
      rainbow-delimiters.enable = true;
      # Colorize hex colors inline
      nvim-colorizer.enable = true;
      # Fancy popups, etc for vim
      noice = {
        enable = true;
        settings = {
          presets = { 
            bottom_search = true; 
            command_palette = true; 
            long_message_to_split = false; 
            inc_rename = false; 
            lsp_doc_border = true; 
          };
          lsp.hover.enabled = false;
          popupmenu.enabled = false;
        };
      };
      notify = {
        enable = true;
        topDown = true; 
        fps = 60;
        stages = "slide";
      };

    # Nix related
      # Nix language syntax highlighting / file type associations
      nix.enable = true;
      # Run nix develop / shell without exiting vim 
      nix-develop.enable = true;

    # Efficiency 
      # Multicursor support 
      multicursors.enable = true;
      # auto bracket completion 
      nvim-autopairs.enable = true;
      # Indentation guides 
      indent-blankline.enable = true;
      # Surround text blocks 
      vim-surround.enable = true;
      # Automatic indent
      intellitab.enable = true;
      # Better yank 
      yanky.enable = true;

    # Layout Related
      # winbar that uses nvim-navic in order to get LSP context from your language server.
      barbecue.enable = true;
      # tab bar like Firefox or Chrome
      bufferline = { 
        enable = true;
        settings = {
          options = {
            separatorStyle = "padded_slope";
            color_icons = false;
            always_show_bufferline = false;
            show_buffer_close_icons = false;
             offsets = [{
              filetype = "NvimTree";
              text = "File Explorer";
              highlight = "EcovimNvimTreeTitle";
              text_align = "center";
              separator = true;
            }];
         };
        };
      };

      # sidebar file browser
      nvim-tree = {
        enable = true;
        diagnostics.enable = true;
        tab.sync.close = true;
        renderer = {
          highlightModified = "icon";
          highlightOpenedFiles = "all";
          indentMarkers.enable = true;
        };
      };
      # Terminal in vim
      toggleterm.enable = true;
      # Alerts / CodeActions 
      trouble = {
        enable = true;
        settings = {
          auto_close = true;
          # cycle_results = false;
          # height = 14;
          # win_config = {
          #   border = "rounded";
          # };
         };
      };

    # Code Related
      # Parser generator tool
      treesitter.enable = true;
      # Status column with click hanlers 
      statuscol = {
        enable = true;
        settings = {
          bt_ignore = null;
          clickhandlers = {
            FoldClose = "require('statuscol.builtin').foldclose_click";
            FoldOpen = "require('statuscol.builtin').foldopen_click";
            FoldOther = "require('statuscol.builtin').foldother_click";
            Lnum = "require('statuscol.builtin').lnum_click";
          };
          clickmod = "c";
          ft_ignore = null;
          relculright = true;
          segments = [
            {
              click = "v:lua.ScFa";
              text = [
                "%C"
              ];
            }
            {
              click = "v:lua.ScSa";
              text = [
                "%s"
              ];
            }
            {
              click = "v:lua.ScLa";
              condition = [
                true
                {
                  __raw = "require('statuscol.builtin').not_empty";
                }
              ];
              text = [
                {
                  __raw = "require('statuscol.builtin').lnumfunc";
                }
                " "
              ];
            }
          ];
          setopt = true;
          thousands = ".";
        };
      };
      
      # List of linters for nixvim
      lint = {
        enable = true;
        lintersByFt = {
          text = ["vale"];
          json = ["jsonlint"];
          markdown = ["vale"];
          rst = ["vale"];
          ruby = ["ruby"];
          janet = ["janet"];
          inko = ["inko"];
          clojure = ["clj-kondo"];
          dockerfile = ["hadolint"];
          terraform = ["tflint"];
          yaml = ["yamllint"];
          nix = ["nix"];
        };
      };
      
      # Popup to show shortcuts
      which-key = {
        enable = true;
        settings.win.border = "rounded";
        settings.spec = [
          {
            __unkeyed-1 = "<leader>b";
            group = "Buffers";
            icon = "󰓩 ";
          }
          {
            __unkeyed-1 = "<leader>c";
            group = "Colorschemes";
            icon = "󰉦 ";
          }
          {
            __unkeyed-1 = "<leader>g";
            group = "Git";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>l";
            group = "LSP";
            icon = "" ;
          }
          {
            __unkeyed-1 = "<leader>n";
            group = "NvimTree / Noice";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>t";
            group = "Trouble";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>m";
            group = "MultiCursor...";
            icon = "󰇀";
          }
          {
            __unkeyed-1 = "<leader>T";
            group = "ToggleTerm";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>w";
            group = "Windows";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>wo";
            group = "Open New...";
            icon = " ";
          }
          {
            __unkeyed-1 = "<leader>wr";
            group = "Resize";
            icon = "󰩨 ";
          }
          {
            __unkeyed-1 = "<window>m";
            group = "Milticursor";
            icon = "󰇀 ";
          }
          {
            __unkeyed-1 = "<leader>o";
            group = "Ollama...";
            icon = "󱜸 ";
          }
        ];
      };

      # Airline / Powerline alternative
      lualine = {
        enable = true;
        settings = {
          componentSeparators = {
            right = "«";
            left = "»";
          };
          sectionSeparators = {
            right = "";
            left = "";
          };
        };
      };

      telescope = {
        enable = true;
        extensions.fzf-native.enable = true;
        keymaps = {
          "<leader><leader>" = {
            action = "find_files";
            options.desc = "Search files by name";
          };
          "<leader>d" = {
            action = "todo-comments";
            options.desc = "TODO Comments";
          };
          "<leader>s" = {
            action = "live_grep";
            options.desc = "Search by live grep";
          };
          "<leader>bl" = {
            action = "buffers";
            options.desc = "[L]list open [B]uffers";
          };
          "<leader>h" = {
            action = "help_tags";
            options.desc = "Search [H]elp";
          };
          "<leader>W" = {
            action = "grep_string";
            options.desc = "Search for [W]ord under cursor";
          };
          "<leader>gs" = {
            action = "git_status";
            options.desc = "Search [G]it [S]tatus";
          };
          "<leader>gl" = {
            action = "git_commits";
            options.desc = "View [G]it [L]ogs";
          };
          "<leader>r" = {
            action = "oldfiles";
            options.desc = "Search [R]ecently opened files by name";
          };
          "<leader>cs" = {
            action = "colorscheme";
            options.desc = "Change [C]olor[s]cheme";
          };
        };
      };
   };

    colorschemes = {
      tokyonight.enable = true;
      gruvbox.enable = true;
      catppuccin.enable = true;
      dracula.enable = true;
      oxocarbon.enable = true;
      ayu.enable = true;
      kanagawa.enable = true;
    };

    extraPlugins = with pkgs.vimPlugins; [
      everforest
      onedark-nvim
      rose-pine
      rust-vim
      outline-nvim
    ];
  };
}