LGUG2Z / JeezyVim

A fast, reliable NeoVim configuration as a Nix Flake for people who want to use NeoVim as an editor and not as an IDE
22 stars 6 forks source link

unsupported attribute `keymaps'. #3

Closed bashfulrobot closed 3 months ago

bashfulrobot commented 3 months ago

Hi there,

I was starting to configure jeezyvim for my needs, but the code is complaining about the location of the keymaps. I compared it against the README, and it "looks" ok to me. I am just trying to determine if it is an issue with my code, or something else within your repo.

This might be because I am trying to create my own module to "enable" jeezyvim on my system with my config.

IE

options = {
    cli.nvim.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = "Enable jeezyvim editor.";
    };
  };

vs

options = { textwidth = 120; };

Thank you!

(loving the approach on this flake.)

CODE

{ pkgs, config, lib, ... }:
let
  cfg = config.cli.nvim;
  username = if builtins.getEnv "SUDO_USER" != "" then
    builtins.getEnv "SUDO_USER"
  else
    builtins.getEnv "USER";
in {

  options = {
    cli.nvim.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = "Enable jeezyvim editor.";
    };
  };

  config = lib.mkIf cfg.enable {

    home-manager.users."${username}" = {
      home = {

        # packages = with pkgs;
        #   [
        #     jeezyvim # opinionated neovim
        #   ];

        sessionVariables = { EDITOR = "nvim"; };

        packages = [
          (pkgs.jeezyvim.nixvimExtend {
            # you can put anything under the "Options" section of the NixVim docs here
            # https://nix-community.github.io/nixvim/

            # some examples...

            # all your regular vim options here
            options = { textwidth = 120; };

            # add your own personal keymaps preferences
            keymaps = [

              # toggle comments
              {
                mode = "n";
                action = ":CommentToggle<CR>";
                key = "<Space>/";
              }
              # toggle copilot-chat
              {
                mode = "n";
                action = ":CopilotChatToggle<CR>";
                key = "<Space>c";
              }
              # explain the active selection
              {
                mode = "n";
                action = ":CopilotChatExplain<CR>";
                key = "<Leader>e";
              }
              # review the selected code
              {
                mode = "n";
                action = ":CopilotChatReview<CR>";
                key = "<Leader>r";
              }
              # fix the selected code
              {
                mode = "n";
                action = ":CopilotChatFix<CR>";
                key = "<Leader>f";
              }
              # optimize the selected code
              {
                mode = "n";
                action = ":CopilotChatOptimize<CR>";
                key = "<Leader>o";
              }
              # add documentation for the selection
              {
                mode = "n";
                action = ":CopilotChatDocs<CR>";
                key = "<Leader>d";
              }
              # generate tests for the code
              {
                mode = "n";
                action = ":CopilotChatTests<CR>";
                key = "<Leader>t";
              }
              # {
              #   mode = "n";
              #   action = ":vsplit<CR>";
              #   key = "|";
              # }

              # {
              #   mode = "n";
              #   action = ":split<CR>";
              #   key = "-";
              # }
            ];

            plugins = {
              lsp.servers = {
                # full list of language servers you can enable on the left bar here:
                # https://nix-community.github.io/nixvim/plugins/lsp/servers/ansiblels/index.html
                bashls.enable = true;
                docker-compose-language-service.enable = true;
                dockerls.enable = false;
                gopls.enable = false;
                graphql.enable = false;
                helm-ls.enable = false;
                html.enable = false;
                htmx.enable = false;
                jsonls.enable = false;
                marksman.enable = false;
                nginx-language-server.enable = false;
                nixd.enable = false;
                pylsp.enable = false;
                rust-analyzer.enable = false;
                svelte.enable = false;
                tailwindcss.enable = false;
                terraformls.enable = false;
                yamlls.enable = false;
              };

              # full list of plugins on the left bar here:
              # https://nix-community.github.io/nixvim/plugins/airline/index.html

              # readme - for config: https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#-configuration
              autoclose.enable = false;
              clipboard-image.enable = false;
              markdown-preview.enable = false;
              copilot-chat.enable = true;
              copilot-cmp.enable = false;
              diffview.enable = false;
              helm.enable = false;
              lazygit.enable = true;
              multicursors.enable = false;
              nix.enable = false;
              nix-develop.enable  = false;
              nvim-colorizer.enable = false;
              obsidian.enable = false;
              todo-comments.enable = false;
            };
          })
        ];
      };
    };
  };
}

ERROR

error: Module `:anon-1:anon-2' has an unsupported attribute `keymaps'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: keymaps plugins) into the explicit `config' attribute.
LGUG2Z commented 3 months ago
        (pkgs.jeezyvim.nixvimExtend {
          # you can put anything under the "Options" section of the NixVim docs here
          # https://nix-community.github.io/nixvim/

          # some examples...

          # all your regular vim options here
          options = {textwidth = 120;};

          config = {
            # add your own personal keymaps preferences
            keymaps = [
              # toggle comments
              {
                mode = "n";
                action = ":CommentToggle<CR>";
                key = "<Space>/";
              }
              # toggle copilot-chat
              {
                mode = "n";
                action = ":CopilotChatToggle<CR>";
                key = "<Space>c";
              }
              # explain the active selection
              {
                mode = "n";
                action = ":CopilotChatExplain<CR>";
                key = "<Leader>e";
              }
              # review the selected code
              {
                mode = "n";
                action = ":CopilotChatReview<CR>";
                key = "<Leader>r";
              }
              # fix the selected code
              {
                mode = "n";
                action = ":CopilotChatFix<CR>";
                key = "<Leader>f";
              }
              # optimize the selected code
              {
                mode = "n";
                action = ":CopilotChatOptimize<CR>";
                key = "<Leader>o";
              }
              # add documentation for the selection
              {
                mode = "n";
                action = ":CopilotChatDocs<CR>";
                key = "<Leader>d";
              }
              # generate tests for the code
              {
                mode = "n";
                action = ":CopilotChatTests<CR>";
                key = "<Leader>t";
              }
              # {
              #   mode = "n";
              #   action = ":vsplit<CR>";
              #   key = "|";
              # }

              # {
              #   mode = "n";
              #   action = ":split<CR>";
              #   key = "-";
              # }
            ];

            plugins = {
              lsp.servers = {
                # full list of language servers you can enable on the left bar here:
                # https://nix-community.github.io/nixvim/plugins/lsp/servers/ansiblels/index.html
                bashls.enable = pkgs.lib.mkForce true;
                docker-compose-language-service.enable = true;
                dockerls.enable = pkgs.lib.mkForce false;
                gopls.enable = pkgs.lib.mkForce false;
                graphql.enable = pkgs.lib.mkForce false;
                helm-ls.enable = pkgs.lib.mkForce false;
                html.enable = pkgs.lib.mkForce false;
                htmx.enable = pkgs.lib.mkForce false;
                jsonls.enable = pkgs.lib.mkForce false;
                marksman.enable = pkgs.lib.mkForce false;
                nginx-language-server.enable = pkgs.lib.mkForce false;
                nixd.enable = pkgs.lib.mkForce false;
                pylsp.enable = pkgs.lib.mkForce false;
                rust-analyzer.enable = pkgs.lib.mkForce false;
                svelte.enable = pkgs.lib.mkForce false;
                tailwindcss.enable = pkgs.lib.mkForce false;
                terraformls.enable = pkgs.lib.mkForce false;
                yamlls.enable = pkgs.lib.mkForce false;
              };

              # full list of plugins on the left bar here:
              # https://nix-community.github.io/nixvim/plugins/airline/index.html

              # readme - for config: https://github.com/m4xshen/autoclose.nvim?tab=readme-ov-file#-configuration
              autoclose.enable = pkgs.lib.mkForce false;
              clipboard-image.enable = pkgs.lib.mkForce false;
              markdown-preview.enable = pkgs.lib.mkForce false;
              # copilot-chat.enable = true; #plugin isn't in nixvim yet?
              copilot-cmp.enable = pkgs.lib.mkForce false;
              diffview.enable = pkgs.lib.mkForce false;
              helm.enable = pkgs.lib.mkForce false;
              lazygit.enable = true;
              multicursors.enable = pkgs.lib.mkForce false;
              nix.enable = pkgs.lib.mkForce false;
              nix-develop.enable = pkgs.lib.mkForce false;
              nvim-colorizer.enable = pkgs.lib.mkForce false;
              obsidian.enable = pkgs.lib.mkForce false;
              todo-comments.enable = pkgs.lib.mkForce false;
            };
          };
        }) # pkgs.jeezyvim

Made some changes here to get what you had compiling, looks like if you have just keymaps or just plugins, it's ok, but if you have both they need to be wrapped in a config block 🤷‍♀️

I think I'll also make some updates to JeezyVim to use pkgs.lib.mkDefault so that users don't have to use pkgs.lib.mkForce to override the default options 🤔