nix-community / nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.78k stars 276 forks source link

Add feature to change NVIM_APPNAME #2334

Open mairs8 opened 1 month ago

mairs8 commented 1 month ago

Description

https://neovim.io/doc/user/starting.html#_nvim_appname

is it possible to change the neovim config directory in nixvim? Usually neovim installs to `.config/nvim' but i don't want to overwrite existing config and instead install to '.config/nixvim'. is this possible? it would be similar to using the $NVIM_APPNAME environment variable in neovim api.

if nixvim does not care about .config directory, there should at least be the ability to install nixvim with different NVIM_APPNAME so that you can use it alongside existing neovim configs.

Minimal, Reproducible Example

see pseudo code below to how i envision changing nvim_appname in nixvim.

programs.nixvim = {
    nvim-appname = "nvim-nixvim"
}
MattSturgeon commented 1 month ago

This could be added. Similar to allowing the exe name to be changed, it could be a useful customization.

Currently it's possible to use a "wrapped" config instead of ~/.config/nvim by setting wrapRc = true and impureRtp = false.

wrapRc will call nvim with -u, telling it to use the init.lua directly from the nix store.

Disabling impureRtp will cause ~/.config.nvim to be removed from the runtimepath.

mairs8 commented 1 month ago

hmmm i am still quite new to neovim and although it's great to see there is a workaround this seems quite complicated which goes against the ethos of nixvim. Is it possible to include such an update as i mention in the psuedo code? i believe this will be a great feature as it will allow people to do parallel installs of nixvim and increase the takeup rate (possibly could be added to readme or install instructions)

MattSturgeon commented 1 month ago

this seems quite complicated which goes against the ethos of nixvim.

Firstly, I don't think the following is especially complex:

programs.nixvim = {
  wrapRc = true;
  impureRtp = false;
}

Secondly, the ethos of nixvim isn't necessarily that everything should be simple. Rather our primary goal is to allow configuring neovim via the nix module system, as transparently as possible, with as little magic happening behind the scenes as possible.

is it possible to include such an update as i mention in the psuedo code?

As I said before: This could be added. Similar to allowing the exe name to be changed, it could be a useful customization.

i believe this will be a great feature as it will allow people to do parallel installs of nixvim

Just having NVIM_APPNAME support (or using a wrapped init via -u) is not enough to allow parallel nixvim installs.

The issue is that nixvim doesn't just install neovim config, it actually installs a nvim exe onto the PATH. Having multiple nixvim installs at the same time would therefore cause conflicts.

Therefore to achive multiple nixvim installs we need to do some additional refactoring, e.g:

mairs8 commented 1 month ago

on related topic, i have installed nixvim but i would like to use it in parallel with my previous config i.e. i have two configs, one which uses programs.neovim.enable and the other that uses makeNixvimWithModule.

How can i run both on same machine in different terminal sessions? apologies if it is provided somewhere in your previous answer, there is alot going on under the hood which a novice like myself can't infer.

MattSturgeon commented 1 month ago

makeNixvimWithModule will use wrapRc internally to tell the nvim it installs to use the init file it builds. So you don't have to worry about init file conflicts.

If you use the nixvim build using makeNixvimWithModule via nix run or nix shell then yes, you can have access to it in a specific shell while still using your "globally installed" neovim elsewhere.

Deliganli commented 1 month ago

I couldn't seem to make it work. Started developing as a standalone flake. Than tried to port to my NixOS setup as an overlay.

    # overlay
    deliganli.novim = let
      system = "x86_64-linux";
      nixvim' = inputs.nixvim.legacyPackages.${system};
      nvim = nixvim'.makeNixvimWithModule {
        pkgs = prev;
        module = import ./novim;
      };
    in nvim;

    # ./novim/default.nix
    {
      # imports
      wrapRc = true;
      impureRtp = false;
    }

    # home config
    # contains my regular neovim setup
    home.file.".config/nvim".source = mkOutOfStoreSymlink "./nvim";

    # shell alias
    "novim" = pkgs.lib.getExe pkgs.deliganli.novim;

~/.config/nvim has the config from home-manager setup. But both novim and the nvim command is using the settings from nixvim

edit: I retried after killing zsh and tmux processes, seems to work with config above. Not sure what was the issue

edit 2: it may be related to whether it is added as home-manager package or system package

  # this makes `nvim` command to work with my old config
  environment.systemPackages = with pkgs; [
    deliganli.novim
  ]

  # this makes `nvim` command to run with nixvim config
  home.packages = with pkgs; [
    deliganli.novim
  ]

Thanks everyone