{
  # Snowfall Lib provides a customized `lib` instance with access to your flake's library
  # as well as the libraries available from your flake's inputs.
  lib,
  # An instance of `pkgs` with your overlays and packages applied is also available.
  pkgs,
  # You also have access to your flake's inputs.
  inputs,

  # Additional metadata is provided by Snowfall Lib.
  system, # The system architecture for this host (eg. `x86_64-linux`).
  target, # The Snowfall Lib target for this system (eg. `x86_64-iso`).
  format, # A normalized name for the system target (eg. `iso`).
  virtual, # A boolean to determine whether this system is a virtual target using nixos-generators.
  systems, # An attribute map of your defined hosts.

  # All other arguments come from the module system.
  config,
  ...
}:

let
  cfg = config.modules.neovim;
in
{
  options.modules.neovim = {
    enable = lib.mkOption { default = false; };
  };

  imports = [ inputs.nixvim.homeManagerModules.nixvim ];

  config = lib.mkIf cfg.enable {
    home.sessionVariables = {
      EDITOR = "nvim";
      VISUAL = "nvim";
    };

    home.packages = with pkgs; [
      git
      gnumake
      gcc
      ripgrep
      fd
      stylua
      black
      nixfmt-rfc-style # nixfmt
    ];

    programs.nixvim = {
      enable = true;
      viAlias = true;
      vimAlias = true;

      colorschemes.catppuccin = {
        enable = true;
        settings.flavour = "mocha";
      };

      globals.mapleader = " ";
      opts = {
        number = false;
        relativenumber = false;

      };
      clipboard.register = "unnamedplus"; # Use system clipboard

      keymaps = [
        {
          action = "<cmd>Telescope live_grep<cr>";
          key = "<leader>/";
        }
        {
          action = "<cmd>Telescope find_files<cr>";
          key = "<leader><space>";
        }
        {
          action = "<cmd>Telescope file_browser<cr>";
          key = "<leader>.";
        }
        {
          action = "<cmd>Neogit<cr>";
          key = "<leader>gg";
        }
        {
          key = "<C-s>";
          action = "<esc><cmd>lua require('conform').format()<cr><cmd>write<cr>";
          mode = [
            "i"
            "x"
            "n"
            "s"
          ];
        }
      ];

      plugins = {
        lualine.enable = true;
        commentary.enable = true;
        which-key.enable = true;
        treesitter.enable = true; # enables all grammar packages
        neogit.enable = true; # like magit
        trouble.enable = true;

        # Shows file trees
        oil = {
          enable = true;
          settings = {
            view_options.show_hidden = true;
          };
        };

        # Code formatting
        conform-nvim = {
          enable = true;
          formattersByFt = with pkgs; {
            lua = [ "stylua" ];
            python = [ "black" ];
            nix = [ "nixfmt" ];
          };
          # extraOptions = {
          #   default_format_opts.lsp_format = "fallback";
          # };
        };

        # autocomplete
        cmp = {
          enable = true;
          autoEnableSources = true;
          settings.sources = [
            { name = "nvim_lsp"; }
            { name = "path"; }
            { name = "buffer"; }
          ];
          settings.mapping = {
            "<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
            "<C-j>" = "cmp.mapping.select_next_item()";
            "<C-k>" = "cmp.mapping.select_prev_item()";
            "<C-e>" = "cmp.mapping.abort()";
            "<CR>" = "cmp.mapping.confirm({ select = true })";
          };
        };

        # Fuzzy finder
        telescope = {
          enable = true;
          settings.defaults.mappings = {
            i = {
              "<C-j>".__raw = "require('telescope.actions').move_selection_next";
              "<C-k>".__raw = "require('telescope.actions').move_selection_previous";
              "<tab>".__raw = "require('telescope.actions').select_default";
            };
          };
          extensions = {
            fzf-native.enable = true;
            file-browser = {
              enable = true;
              settings = {
                hidden = true; # show hidden files
                follow_symlinks = true;
                no_ignore = true;
              };
            };
          };
        };

        lsp = {
          enable = true;
          servers = {
            rust-analyzer = {
              enable = true;
              installCargo = true;
              installRustc = true;
            };
            nixd.enable = true;
            pyright.enable = true;
            dockerls.enable = true;
            lua-ls.enable = true;
          };
        };

      };

    };
  };
}