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

let
  inherit (lib) mkEnableOption mkIf readFile;

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

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

  config = mkIf cfg.enable {
    home-manager.users.moritz = {
      xdg.configFile."nvim/snippets" = {
        recursive = true;
        source = ./plugins/snippets;
      };

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

      programs.neovim = {
        enable = true;
        package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default;
        vimAlias = true;
        vimdiffAlias = true;
        withNodeJs = true;
        withPython3 = true;
        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
          ];
        extraLuaConfig = readFile ./options.lua;
        lazy.enable = true;
      };
    };
  };
}
