Skip to content
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

Build plugin specs as derivations #6

Open
willruggiano opened this issue Mar 15, 2024 · 6 comments
Open

Build plugin specs as derivations #6

willruggiano opened this issue Mar 15, 2024 · 6 comments
Labels
enhancement New feature or request good second issue More involved than just "good for beginners" lol

Comments

@willruggiano
Copy link
Owner

Right now, the entire lazy spec is defined "in a single derivation". Better - I think - would be to build each plugin individually (which we already do) and attach to it (e.g. via passthru) its lazy spec (as a derivation). This is more in line with how flake-parts is organized.

@willruggiano willruggiano added enhancement New feature or request good second issue More involved than just "good for beginners" lol labels Mar 15, 2024
@willruggiano
Copy link
Owner Author

Doing it this way would also allow for breaking up the plugin specs as is mentioned here; https://github.com/folke/lazy.nvim?tab=readme-ov-file#-structuring-your-plugins

Might be nice.

@willruggiano
Copy link
Owner Author

re: passthru.lazy-spec (or whatever)

it would allow cpath (newly added) to be a function, so instead of:

  lfs = let
    package = luajitPackages.luafilesystem;
  in {
    inherit package;
    cpath = "${package}/lib/lua/5.1/?.so";
  };

you could do

  lfs = {
    package = luajitPackages.luafilesystem;
    cpath = drv: "${drv}/lib/lua/5.1/?.so";
  };

https://github.com/willruggiano/neovim.drv/blob/main/plugins/spec.nix#L269-L274

@willruggiano
Copy link
Owner Author

another interesting approach would be more like dream2nix, so the "plugin spec" could import modules

e.g. https://github.com/nix-community/dream2nix/blob/main/examples/packages/basics/mkDerivation/default.nix

@nekowinston
Copy link
Contributor

Does that mean turning the single LazySpec we build atm to a LazySpec[], generating a Lua file for each plugin, then importing them like

vim.opt.rtp:prepend "${cfg.package}"
vim.opt.rtp:prepend "${cfg.plugins}" -- symlinkJoin of all plugins or similar
require("lazy").setup({
  spec = {
    { import = "nvim-treesitter" }, -- loading the lua configs from the plugin rtp
    { import = "which-key" },
    -- ... etc
  },
})

I'd also like to have a way to add custom Lua specs in there, so that you could configure the plugin package via Nix, and then use Lua with the opts override pattern that's common in LazyVim, e.g:

return {
  {
    name = "myplugin",
    opts = function(_, opts)
      opts.some_override = "foo"
    end
  }
}

while defining the package/dir through Nix-built packages.

@willruggiano
Copy link
Owner Author

re: generating a Lua file per plugin

Yes, I think that's what I meant.

@willruggiano
Copy link
Owner Author

re: custom Lua specs

I think we should able to support basically anything if we're strategic about how we integrate with lazy. Specifically this part of the docs;

When you import specs, you can override them by simply adding a spec for the same plugin to your local specs, adding any keys you want to override / merge.

https://lazy.folke.io/usage/structuring#%EF%B8%8F-importing-specs-config--opts

This seems like it maps really well into Nix - it reminds me a lot of flake-parts.

I'll add some more comments here this week hopefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good second issue More involved than just "good for beginners" lol
Projects
None yet
Development

No branches or pull requests

2 participants