nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

Feat - Export portable neovim configuration

Open PowerUser64 opened this issue 3 months ago • 6 comments

I think it would be really cool if nixvim could export a portable version of the configuration files it generates. This would allow configurations to be more easily used in limited environments such as servers where a nix binary might not exist, or there could be other restrictions related to installing additional software. Also, it could make it easier to use on other platforms such as windows.

Related: https://github.com/ralismark/nix-appimage, https://github.com/DavHau/nix-portable

PowerUser64 avatar Mar 28 '24 23:03 PowerUser64

I think exporting to windows is going to be very hard, because nixvim does not only bundle the user configuration & plugins, but also adds a lot of programs like LSPs, linters, formmaters,...

I think If you build your configuration as a standalone nixvim module you could use https://github.com/ralismark/nix-appimage without any support on our side

traxys avatar Mar 29 '24 09:03 traxys

While I agree this would be a great feature to have, I can't think of a practical way to do it.

Some basics like options, globals, & keymaps could probably be done, but anything that uses plugins or packages from nixpkgs would be very difficult to make portable.

I believe there are other nix/vim frameworks that may be more suitable to portable configs, though I'm on my phone currently so I don't have any links.

I've been thinking about using a nixvim config to generate other non-nixvim files, such as vimrc, ideavimrc, etc...

Maybe the standalone nixvim build could also contain a config attribute which would be the final config evaluated by the module system. That could then be used by end-users to share some basics parts of the config in other files they write... Subject to all the same limitations mentioned above, of course.

MattSturgeon avatar Mar 29 '24 20:03 MattSturgeon

Some basics like options, globals, & keymaps could probably be done, but anything that uses plugins or packages from nixpkgs would be very difficult to make portable.

I figured, yeah. The output would probably have to at least exclude compiled things like LSP's and prebuilt treesitter modules. The nvim treesitter plugin can download+compile parsers on its own, so at least treesitter-powered highlighting is portable. As for language servers, we'd probably want to disable or ommit them in a way that they could still be enabled if the target system has them. (maybe just comment each of them out?)

Loading plugins is the thing I'm most unsure of. It would be super cool if plugins could be bundled up too, because plugins can be very important to how some configurations work. Is there anything about bundling plugins that you were specifically thinking would be difficult?

I've been thinking about using a nixvim config to generate other non-nixvim files, such as vimrc, ideavimrc, etc...

Ooh, that would be really cool too!

PowerUser64 avatar Mar 29 '24 21:03 PowerUser64

The nvim treesitter plugin can download+compile parsers on its own, so at least treesitter-powered highlighting is portable.

If my understanding is correct, it's not even that simple. Any part of nixvim that references another package will be rendered as a reference to the nix store (/nix/store).

If nixvim includes some treesitter package or some pkgs.vimPlugins.foobar anywhere, then you have a hard dependency on nix.

E.g. When nixvim sets up a nvim-treesitter, it isn't just writing (e.g.) "json", it's getting pkgs.vimPlugins.nvim-treesitter-parsers.json and writing its nix store path in your init.lua.

(I haven't actually looked at this code, but this is how nix configs are supposed to work)

If you want portability, you cannot reference any nix packages at all in the file you write. This almost defeats the point of nix; providing the same dependencies on all installations.

MattSturgeon avatar Mar 29 '24 21:03 MattSturgeon

Yeah I think the only way anything can be done is using https://github.com/ralismark/nix-appimage.

I tested it on my own configuration, and it seemed to work pretty well, for example rust-analyzer worked!

traxys avatar Mar 29 '24 21:03 traxys

Do you think it could work if nix store paths were substituted for relative paths? Maybe that's getting a bit out of scope for what such a feature should provide though. It sounds like nix-appimage (or probably nix-bundle) can do this even better, so that might just have to be the way to go for the more complicated task of keeping all plugins.

It's probably better for this issue to be about outputting vim-native options and keybinds for neovim, vim, and other places vim is found like @MattSturgeon you were saying.

PowerUser64 avatar Mar 30 '24 05:03 PowerUser64