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

programs.neovim: init #98506

Merged
merged 2 commits into from Sep 28, 2020
Merged

programs.neovim: init #98506

merged 2 commits into from Sep 28, 2020

Conversation

teto
Copy link
Member

@teto teto commented Sep 22, 2020

Allows to build a proper runtime folder with after/ ftplugin/ parser/ subfolders etc.
(neo)vim expects a few different folders, for instance to load
treesitter parsers.

This PR reuses the builder from the etc module, notwithstanding the
different modes/uid/gid.

This allows to get rid of some autocmd in customRC (via proper use of
the folder hierarchy) which is a win in my opinion.

Motivation for this change

I find strange to use a systemwide module for an editor but #55635 was too ambitious this I prefer to do it step by step. The (neo)vim configuration is not trivial and the module system with the typecheck is quite useful. The ability to reproduce a proper runtime folder is quite useful to alleviate the customrc writing but also to install treesitter parsers alongside neovim. I plan to improve the module later but right now I use it with

{ config, lib, pkgs,  ... }:
{
  programs.neovim = {
    enable = true;
    package = pkgs.neovim-unwrapped-master;

    configure = pkgs.neovimConfigure // {
      customRC = (pkgs.neovimConfigure.customRC  or "") + ''
        let g:fzf_command_prefix = 'Fzf' " prefix commands :Files become :FzfFiles, etc.
        let g:fzf_nvim_statusline = 0 " disable statusline overwriting
        source ~/.config/nvim/init.vim
      '';

    };

    runtime."ftplugin/bzl.vim".text = ''
      setlocal expandtab
    '';

    runtime."ftplugin/c.vim".text = ''
      " otherwise vim defaults to ccomplete#Complete
      setlocal omnifunc=v:lua.vim.lsp.omnifunc

    '';


    # cp $(nix-build -A tree-sitter.builtGrammars."$lang" ~/nixpkgs)/parser config/nvim/parser/${lang}.so
    runtime."parser/c.so".source = "${pkgs.tree-sitter.builtGrammars.c}/parser";
    runtime."parser/bash.so".source = "${pkgs.tree-sitter.builtGrammars.bash}/parser";
  };

}

@timokau

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@timokau
Copy link
Member

timokau commented Sep 23, 2020

I worry a bit about adding yet another dimension to the "how have you set up your neovim configuration in nix(os)". Could you expand a bit on the motivation? I'm not entirely sure I understand it completely. Is this mainly about the ability of adding files to ftplugin? Couldn't we somehow achieve that with the wrapper as well, for example by adding a custom prefix somehow?

Besides that, having it documented in man configuration.nix is and advantage of course.

@teto
Copy link
Member Author

teto commented Sep 23, 2020

I think an editor would be best configured on a per-basis project too but right now that's too hard. The configure attrset is a mess etc.
The module system provides:

  • type checking/ discoveribility as you mentioned
  • it makes the ability to compose a proper runtime with the filehierarchy supported by (neo)vim. For instance I have this hierarchy https://github.com/teto/home/tree/master/config/nvim (and it's missing treesitter queries / parsers that are not versioned). You can
    have several runtime."ftplugin/c.vim".text = '' that will be concatenated and all.

I've been frustrated long enough with the nix vim configuration system and this is the smallest PR I could put that fixed it. I have tried to build the runtime in vim-utils but it was just too hard and not as powerful as the module system. I do plan to improve the vim-utils.nix file (I have some local changes too) but little by little.

Copy link
Member

@timokau timokau left a comment

Choose a reason for hiding this comment

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

Alright, I'll trust your judgement on the "why" then. Left some comments on the "what".

nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
'';
description = ''
Generate your init file from your list of plugins and custom commands,
and loads it from the store via <command>nvim -u /nix/store/hash-vimrc</command>
Copy link
Member

Choose a reason for hiding this comment

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

Grammar seems off. Maybe "Generate your init file from your list of plugins and custom commands. neovim will then be wrapped to add the -u /nix/store/hash-vimrc flag." (or similar).

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I got this, I updated the description though.

nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
@timokau
Copy link
Member

timokau commented Sep 23, 2020

How does this relate with the neovim module in home-manager?

Copy link
Member

@timokau timokau left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me now, except some minor formatting things. The question about the relation to home-manager still remains though. My worry is that we now have at least three (.override, nixos-module, home-manager module) just-so-slightly different ways to configure neovim. That might add to the confusion. What do you think? Maybe this should at least match the home-manager UX exactly, or we keep it in home-manager entirely and just suggest people to use that.

nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
nixos/modules/programs/neovim.nix Outdated Show resolved Hide resolved
Allows to build a proper runtime folder with after/ ftplugin/ parser/ subfolders etc.
(neo)vim expects a few different folders, for instance to load
treesitter parsers.

This PR reuses the builder from the etc module, notwithstanding the
different modes/uid/gid.

This allows to get rid of some autocmd in customRC (via proper use of
the folder hierarchy) which is a win in my opinion.
@teto
Copy link
Member Author

teto commented Sep 28, 2020

thanks for the reviews, I tried to address them. I used to be adamant about home-manager and nixos modules convergence but it's clear it's not happening anytime soon. Thus I don't think it's a problem if they diverge (I kinda keep an eye on both). My goal is to let the module remain a thin interface wrapper around better vim-utils.nix functions. Having a module in the same repository as the utilities makes the task easier IMO (and we may experiment a bit more in HM).

@timokau
Copy link
Member

timokau commented Sep 28, 2020

Alright. I still think it would be desirable to match the HM and NixOS modules from an UX perspective (even if the implementation differs). I understand your point too though. Your call :)

@teto teto merged commit 1e510a6 into NixOS:master Sep 28, 2020
@teto teto deleted the neovim_module2 branch September 28, 2020 15:07
'';
description = ''
Generate your init file from your list of plugins and custom commands.
Neovim will then be wrapped to load <command>nvim -u /nix/store/<hash>-vimrc</command>
Copy link
Member

Choose a reason for hiding this comment

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

building '/nix/store/f49frvgmnk7j528awy3z45p36rc3rhcl-options-docbook.xml.drv'...
intermediate.xml:8247: parser error : Opening and ending tag mismatch: hash line 8247 and command
m will then be wrapped to load <command>nvim -u /nix/store/<hash>-vimrc</command
                                                                               ^
intermediate.xml:8248: parser error : Opening and ending tag mismatch: command line 8247 and para
</para></nixos:option-description><para><emphasis>Type:</emphasis> attribute set
       ^
intermediate.xml:8248: parser error : Opening and ending tag mismatch: para line 8247 and nixos:option-description
</para></nixos:option-description><para><emphasis>Type:</emphasis> attribute set
                                  ^
intermediate.xml:8267: parser error : Opening and ending tag mismatch: option-description line 8247 and listitem
            </filename></member></simplelist></listitem></varlistentry><varliste
                                                        ^
intermediate.xml:8267: parser error : Opening and ending tag mismatch: listitem line 8247 and varlistentry
            </filename></member></simplelist></listitem></varlistentry><varliste
                                                                       ^
intermediate.xml:75124: parser error : Opening and ending tag mismatch: varlistentry line 8247 and variablelist
      </filename></member></simplelist></listitem></varlistentry></variablelist>
                                                                               ^
intermediate.xml:75124: parser error : Opening and ending tag mismatch: variablelist line 8247 and appendix
lename></member></simplelist></listitem></varlistentry></variablelist></appendix
                                                                               ^
intermediate.xml:75126: parser error : EndTag: '</' not found

^
unable to parse intermediate.xml

This will probably block the unstable-small channel.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, it was already reverted.

Copy link
Member

Choose a reason for hiding this comment

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

In a fork… github's UI is complicated.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a fork for the revert/fix of this?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I will commit a fix

Copy link
Member Author

Choose a reason for hiding this comment

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

here #99023

Copy link
Member Author

Choose a reason for hiding this comment

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

@ajs124 does that fix it for you ? I dont have the resorces to build on master but it looked fine.

@deviant
Copy link
Member

deviant commented Oct 20, 2020

The defaultEditor option doesn't do anything and enabling this module unconditionally configures neovim as the default editor.

Edit: this would be fixed by #101127

@teto
Copy link
Member Author

teto commented Oct 20, 2020

thanks for the notification, looking forward to #101127

configure = cfg.configure // {

customRC = (cfg.configure.customRC or "") + ''
set runtimepath^=${runtime}/etc
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why this appends the /etc and not just the runtime path?

Since, as far as I can tell, the runtime in the config attribute sets them directly in the path and not in etc. For example, for a tree-sitter parser need to put them in the etc/parser/foo.so to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants