{ config, lib, pkgs, inputs, ... }:

let
  inherit (lib) mkEnableOption mkIf readFile;

  cfg = config.my.programs.nvim;
in
{
  imports = lib.my.listModulesRec ./new_plugins;

  options.my.programs.nvim.enable = mkEnableOption "nvim";

  config = mkIf cfg.enable {
    home-manager.users.moritz = {

      home.packages = with pkgs; [
        xdotool # for vimtex
      ];

      #   programs.neovim = {
      #     extraPackages = with pkgs;
      #       [
      #         alejandra
      #         checkmake
      #         codespell
      #         deadnix
      #         dotenv-linter
      #         fish
      #         jq
      #         nil
      #         nixd
      #         nixpkgs-fmt
      #         nodePackages.bash-language-server
      #         python3Packages.python-lsp-server
      #         shellcheck
      #         shfmt
      #         stable.yamlfix
      #         statix
      #         taplo
      #         yamllint
      #       ];
      #   };

      programs.nixvim = {
        enable = true;
        package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default;
        vimAlias = true;
        extraConfigLuaPre = readFile ./options.lua;
        luaLoader.enable = true;
        performance = {
          byteCompileLua = {
            enable = true;
            configs = true;
            initLua = true;
            nvimRuntime = true;
            plugins = true;
          };
          combinePlugins.enable = true;
        };
      };
    };
  };
}