Skip to content

plugins/lazy.nvim: switch to mkNeovimPlugin #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

my7h3le
Copy link

@my7h3le my7h3le commented Aug 25, 2024

This PR came about as a result of the comments made in this PR #1904. It refactors the existing lazy plugin manager to use mkNeovimPlugin and makes the plugin type freeform.

Closes #2174 #1904

Here's an example of how to set up LazyVim using the changes to this plugin (Note: this is a standalone flake, saving it to any directory as flake.nix and running nix build should be enough, to launch neovim run ./result/bin/nvim)

# flake.nix

{
  description = "Setup LazyVim using NixVim";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nixvim.url = "github:my7h3le/nixvim/lazy-plugin-manager-freeform";
  inputs.nixvim.inputs.flake-parts.follows = "flake-parts";
  inputs.flake-parts.url = "github:hercules-ci/flake-parts";
  inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";

  outputs =
    {
      self,
      nixpkgs,
      nixvim,
      flake-parts,
    }@inputs:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [
        "aarch64-darwin"
        "aarch64-linux"
        "x86_64-darwin"
        "x86_64-linux"
      ];

      perSystem =
        {
          pkgs,
          lib,
          system,
          ...
        }:
        let
          config = {

            # This path is required to be added at runtime at the beginning of
            # the `init.lua` file for `nvim-treesitter`'s parser_install_dir
            # option to work correctly. Unfortunately `nvim-treesitter`
            # requires the parser installation directory to be read-writeable
            # so it can't be in a path in the nix store.
            extraConfigLuaPre = ''
              vim.opt.runtimepath:prepend(vim.fs.joinpath(vim.fn.stdpath("data"), "site"))
            '';

            plugins = {
              lazy = {
                enable = true;
                settings = {
                  defaults = {
                    # When true `lazy.nvim` will lazy load all plugins by default (`lazy.nvim` sets this
                    # to false by default). 
                    lazy = false;
                  };
                  install = {
                    # Don't install missing plugin dependencies.
                    missing = false;
                  };
                  dev = {
                    # Prevent `lazy.nvim` from fallbacking to fetch plugins
                    # from GitHub. You can set this to true as well.
                    fallback = false;
                  };
                  performance = {
                    rtp = {
                      # Disable some rtp plugins
                      disabled_plugins = [
                        "gzip"
                        "matchit"
                        "matchparen"
                        "netrwPlugin"
                        "tarPlugin"
                        "tohtml"
                        "tutor"
                        "zipPlugin"
                        "gzip"
                        "tarPlugin"
                        "tohtml"
                        "zipPlugin"
                      ];
                    };
                  };
                };

                plugins =
                  with pkgs.vimPlugins;
                  [
                    {
                      pkg = LazyVim;
                      import = "lazyvim.plugins";
                      # LazyVim needs `trouble-nvim` specified as a dependency
                      dependencies = trouble-nvim;
                    }
                    {
                      pkg = nvim-treesitter;
                      opts = {
                        ensure_installed = [
                          "vim"
                          "regex"
                          "lua"
                          "bash"
                          "markdown"
                          "markdown_inline"
                        ];
                        highlight = {
                          enable = true;
                        };
                        parser_install_dir.__raw = ''vim.fs.joinpath(vim.fn.stdpath("data"), "site")'';
                      };
                    }
                    {
                      pkg = telescope-fzf-native-nvim;
                      enabled = true;
                    }
                    {
                      pkg = mason-nvim;
                      enabled = false;
                    }
                    {
                      pkg = mason-lspconfig-nvim;
                      enabled = false;
                    }
                    luvit-meta
                    bufferline-nvim
                    grug-far-nvim
                    tokyonight-nvim
                    cmp-buffer
                    cmp-nvim-lsp
                    cmp-path
                    trouble-nvim
                    conform-nvim
                    dashboard-nvim
                    dressing-nvim
                    flash-nvim
                    friendly-snippets
                    gitsigns-nvim
                    indent-blankline-nvim
                    lazydev-nvim
                    lualine-nvim
                    neo-tree-nvim
                    noice-nvim
                    nui-nvim
                    nvim-autopairs
                    nvim-cmp
                    nvim-lint
                    nvim-lspconfig
                    nvim-notify
                    nvim-ts-autotag
                    nvim-snippets
                    nvim-spectre
                    nvim-treesitter-textobjects
                    persistence-nvim
                    plenary-nvim
                    telescope-nvim
                    todo-comments-nvim
                    ts-comments-nvim
                    which-key-nvim
                  ]
                  ++
                    # nix bundles all `mini-nvim` modules together, but LazyVim
                    # expects individual `mini.nvim` modules so map their
                    # individual names to the bundled `mini-nvim` package.
                    lib.map
                      (mini-module: {
                        name = "${mini-module}";
                        pkg = pkgs.vimPlugins.mini-nvim;
                      })
                      [
                        "mini.ai"
                        "mini.icons"
                        "mini.move"
                        "mini.nvim"
                        "mini.pairs"
                        "mini.splitjoin"
                        "mini.trailspace"
                      ];
              };
            };

          };
          nixvim' = nixvim.legacyPackages."${system}";
          nvim = nixvim'.makeNixvim config;
        in
        {
          packages = {
            inherit nvim;
            default = nvim;
          };
        };
    };
}

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch 4 times, most recently from 2ca79f3 to 8230165 Compare September 1, 2024 08:37
@my7h3le

This comment was marked as resolved.

@MattSturgeon

This comment was marked as resolved.

@my7h3le

This comment was marked as resolved.

@MattSturgeon

This comment was marked as resolved.

@my7h3le

This comment was marked as resolved.

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch from 85482f0 to 4473f5c Compare September 1, 2024 11:47
@my7h3le my7h3le changed the title plugins/lazy.nvim: Add freeform setup option & Make existing pluginType freeform plugins/lazy.nvim: switch to mkNeovimPlugin Sep 1, 2024
@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch 3 times, most recently from 71f83e8 to 5a7b6c0 Compare September 1, 2024 12:35
@MattSturgeon
Copy link
Member

Seems there's two errors being picked up by CI currently, both part of the test-17 group:

error: builder for '/nix/store/XXX-empty.drv' failed with exit code 1;
       last 8 log lines:
       > ERROR: Error detected while processing /nix/store/6kqddn2g51j1lvbqsv6v17f6565ihpbk-init.lua:
       > Invalid plugin spec {
       >   dev = {
       >     fallback = false,
       >     path = "/nix/store/k71lsglx88q8ycaqj8vrj56hh80r4ccw-lazy-plugins",
       >     patterns = { "." }
       >   }
       > }

And

error: builder for '/nix/store/XXX-test.drv' failed with exit code 1;
       last 1 log lines:
       > ERROR: gitsigns: git not in path. Aborting setup

@my7h3le
Copy link
Author

my7h3le commented Sep 1, 2024

test-17 group

Hmmm I did see that and I think I have some ideas on how to fix it. Do you know how to run just the test-17 group? This doesn't work nix flake check checks.aarch64-linux.test-17 and I've been running nix flake check --all-systems

@MattSturgeon
Copy link
Member

MattSturgeon commented Sep 1, 2024

Do you know how to run just the test-17 group?

You can do nix build .#checks.<system>.test-17 (replace <system> as appropriate).

If you enter a devshell, you can also use our tests command to run a specific test from within that group, e.g. interactively with tests -i or by specifying the test name on the command line tests plugins-pluginmanagers-lazy.

Further, if you don't want to use a devshell, you can still get at individual tests within a group by using the entries passthru (tab-completion can help here).

E.g. nix build .#checks.x86_64-linux.test-17.entries.plugins-pluginmanagers-lazy --show-trace

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch 9 times, most recently from 1e52f22 to a128e90 Compare September 2, 2024 20:09
Copy link
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was able to simplify the pluginToLua function, I'll add that as a temporary commit to this PR, and if it's deemed as appropriate for this PR itself I can squash it but if not I'll move it into it's own separate PR

Looks much better. I think it makes sense as part of this PR.

I only really went over this part of the PR in this review, but I'll try and find time to fully review soon as everything seems to be coming together 😀

@my7h3le
Copy link
Author

my7h3le commented Nov 17, 2024

I just wanted to comment because I know I haven’t made any updates to this PR in a while. This PR is a priority for me, but I haven’t been able to find the time to work on it, and I’m currently without a computer at the moment. I will try to get it done before the holidays, but it may take me longer to get around to it.

It is a big refactor all and it should be done well

@Mikilio
Copy link

Mikilio commented Dec 29, 2024

I noticed that the build spec is missing. Is there a reason for that? Should I instead use nix override for that? Couldn't this module do it instead?

@my7h3le
Copy link
Author

my7h3le commented Feb 16, 2025

Just as by way of an update, I've finally been able to get around to looking at this again. It's been a while since I've looked at the code for this but hopefully will have the PR fleshed out enough for a merge in the coming days

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch from 64eff65 to deb91ca Compare May 12, 2025 01:52
@my7h3le
Copy link
Author

my7h3le commented May 12, 2025

I know it's pretty long overdue, and sorry to anyone that's been holding out for this! Just got around to taking a look at this after a long while so I'll probably be a bit rusty. I'd definitely appreciate a couple of eyes on this.

Edit: I'm going to move the PR back to draft stage, as I take care of miscellaneous minor edits and suggestions like better descriptions etc. But please feel free to take a look at the PR still and give suggestions :)

@my7h3le my7h3le marked this pull request as ready for review May 12, 2025 01:57
@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch 4 times, most recently from 7e185d2 to a85dbef Compare May 12, 2025 02:10
@my7h3le my7h3le marked this pull request as draft May 12, 2025 02:16
@my7h3le
Copy link
Author

my7h3le commented May 12, 2025

I noticed that the build spec is missing. Is there a reason for that? Should I instead use nix override for that? Couldn't this module do it instead?

Sorry about the late response, and yes you're correct that is missing but it isn't necessary to be explicitly defined here. The reason being is that that each plugin is defined as a freeformType so any options that aren't explicitly declared can still be passed through.

package = "lazy-nvim";

# TODO: remove this
deprecateExtraOptions = true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed as there is this:

dependencies.git.enable = lib.mkDefault true;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implements a rename warning for a legacy option called extraOptions which is now replaced by the freeform settings option.

Setting this to true causes mkNeovimPlugin to add an alias: mkRenamedOptionModule ["plugins" "lazy" "extraOptions"] ["plugins" "lazy" "settings"]

We've probably had the alias long enough that users should've migrated though. See #3181

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will go ahead and remove it then (should be safe to do so now)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was added at the same time as the other rename warnings, it should stay for a while.

They can all be moved to a separate file though if preferred.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I added that as a part of this PR because I saw it in neo-git when I was looking into how dependencies.git was defined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the plugin doesn't currently have an extraOptions option, and never did, so yeah this isn't needed 👍

@my7h3le

This comment was marked as resolved.

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch from a85dbef to cadfa01 Compare May 12, 2025 03:53
@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch from cadfa01 to c187b5b Compare May 12, 2025 04:13
@MattSturgeon
Copy link
Member

MattSturgeon commented May 12, 2025

When running tests using the dev shell I can't apply the --show-trace flag

You should be able to run e.g.:

tests plugins-pluginmanagers-lazy -- --show-trace

The tests command uses the fairly common pattern of -- separating parsed args on the left and literal args passed through to some underlying program on the right.

Some programs also use -- to explicitly separate args from filenames, e.g. git log -- some-file.txt

@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch 6 times, most recently from 2cbac0e to c3cbc29 Compare May 15, 2025 04:48
@my7h3le my7h3le force-pushed the lazy-plugin-manager-freeform branch from c3cbc29 to 711e6be Compare May 15, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants