-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
neovim: expose sideloadInitLua option to control the generation of init.lua
#9028
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
base: master
Are you sure you want to change the base?
Changes from all commits
669baa7
50b090d
f970836
001e4fb
c97e7c8
56fadc9
01fe9de
93a8afb
cf275d0
dc06681
e60886d
f82ea7b
c353b71
e79600c
5775343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,14 @@ in | |
| ''; | ||
| }; | ||
|
|
||
| sideloadInitLua = mkOption { | ||
| type = types.bool; | ||
| default = false; | ||
| description = '' | ||
| Whether to sideload the content of {var}`initLua` without generating a {file}`init.lua`. | ||
| ''; | ||
| }; | ||
|
|
||
| initLua = mkOption { | ||
| type = types.lines; | ||
| default = ""; | ||
|
|
@@ -495,13 +503,6 @@ in | |
| opt = [ ]; | ||
| }; | ||
| }; | ||
|
|
||
| # This is a hack to avoid breaking config for users that dont want an init.lua to get generated | ||
| # See https://github.com/nix-community/home-manager/pull/8734 | ||
| # we basically check if the generated wrapper lua config has any user-set config | ||
| # if not HM avoids creating an init.lua | ||
| # this makes the logic harder to understand and maintain so hopefully we can find a way out | ||
| wrapperHasUserConfig = wrappedNeovim'.luaRcContent != wrappedNeovim'.providerLuaRc; | ||
| in | ||
| { | ||
| programs.neovim = { | ||
|
|
@@ -530,9 +531,9 @@ in | |
|
|
||
| programs.neovim.extraPackages = mkIf cfg.autowrapRuntimeDeps vimPackageInfo.runtimeDeps; | ||
|
|
||
| programs.neovim.extraWrapperArgs = mkIf (!wrapperHasUserConfig) [ | ||
| programs.neovim.extraWrapperArgs = mkIf (cfg.sideloadInitLua && cfg.initLua != "") [ | ||
| "--add-flags" | ||
| ''--cmd 'lua dofile("${pkgs.writeText "wrapper-init-lua" wrappedNeovim'.luaRcContent}")' '' | ||
| ''--cmd 'lua dofile("${pkgs.writeText "wrapper-init-lua" cfg.initLua}")' '' | ||
| ]; | ||
|
|
||
| programs.neovim.initLua = | ||
|
|
@@ -550,7 +551,7 @@ in | |
| null; | ||
| in | ||
| lib.mkMerge [ | ||
| (lib.mkIf wrapperHasUserConfig ( | ||
| (lib.mkIf (wrappedNeovim'.luaRcContent != "") ( | ||
| # we want it to appear rather early | ||
| lib.mkOrder 200 wrappedNeovim'.luaRcContent | ||
| )) | ||
|
|
@@ -577,6 +578,7 @@ in | |
| ++ [ | ||
| { | ||
| "nvim/init.lua" = mkIf (cfg.initLua != "") { | ||
| enable = !cfg.sideloadInitLua; | ||
| text = cfg.initLua; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just add |
||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| { lib, ... }: | ||
| { | ||
| imports = [ ./stubs.nix ]; | ||
|
|
||
| programs.neovim.enable = true; | ||
|
|
||
| nmt.script = '' | ||
| nvimFolder="home-files/.config/nvim" | ||
| assertPathNotExists "$nvimFolder/init.lua" | ||
| initLua="home-files/.config/nvim/init.lua" | ||
| initLuaNormalized="$(normalizeStorePaths "$initLua")" | ||
|
|
||
| assertFileContent "$initLuaNormalized" ${builtins.toFile "init.lua-expected" ( | ||
| lib.trim '' | ||
| vim.g.loaded_node_provider=0;vim.g.loaded_perl_provider=0;vim.g.ruby_host_prog='/nix/store/00000000000000000000000000000000-neovim-ruby-env/bin/neovim-ruby-host';vim.g.python3_host_prog='/nix/store/00000000000000000000000000000000-nvim-host-python3/bin/nvim-python3' | ||
| '' | ||
| )} | ||
| ''; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { pkgs, realPkgs, ... }: | ||
|
|
||
| { | ||
| tests.stubs.wl-clipboard = { }; | ||
|
|
||
| programs.neovim = { | ||
| enable = true; | ||
| package = realPkgs.neovim-unwrapped; | ||
| vimAlias = true; | ||
| withNodeJs = false; | ||
| withPython3 = true; | ||
| withRuby = false; | ||
|
|
||
| sideloadInitLua = true; | ||
|
|
||
| extraPython3Packages = ( | ||
| ps: with ps; [ | ||
| jedi | ||
| pynvim | ||
| ] | ||
| ); | ||
|
|
||
| # plugins without associated config should not trigger the creation of init.vim | ||
| plugins = with pkgs.vimPlugins; [ | ||
| { | ||
| plugin = vim-fugitive; | ||
| type = "viml"; | ||
| config = '' | ||
| let g:hmPluginVimlConfig = 'HM_PLUGIN_VIML_CONFIG' | ||
| ''; | ||
| } | ||
| { | ||
| plugin = vim-sensible; | ||
| type = "lua"; | ||
| config = '' | ||
| vim.g.hmPluginLuaConfig = 'HM_PLUGIN_LUA_CONFIG' | ||
| ''; | ||
| } | ||
| ]; | ||
|
|
||
| extraConfig = '' | ||
| let g:hmExtraConfig = 'HM_EXTRA_CONFIG' | ||
| ''; | ||
|
|
||
| initLua = '' | ||
| vim.g.hmInitLua = 'HM_INIT_LUA' | ||
| ''; | ||
| }; | ||
| nmt.script = '' | ||
| nvimFolder="home-files/.config/nvim" | ||
| nvimBin="home-path/bin/nvim" | ||
| export PATH="$TESTED/home-path/bin:$PATH" | ||
| export HOME="$TMPDIR/hm-user" | ||
| export XDG_CONFIG_HOME="$TESTED/home-files/.config" | ||
|
|
||
| assertNeovimExpr() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems to duplicate an existing function. I would rather see the same function used across tests even if you have to modify it. Move it to a neovim.sh that you can source across tests if that helps. |
||
| local expr="$1" | ||
| local expected_pattern="$2" | ||
| local output=$(nvim -i NONE --headless -c "$expr" +q! 2>&1) | ||
| local exit_code=$? | ||
|
|
||
| if [ $exit_code -ne 0 ]; then | ||
| echo "neovim command failed with code: $exit_code and output:" | ||
| fail "$output" | ||
| elif ! grep "$expected_pattern" <(echo -n "$output") ; then | ||
| echo "Expression '$expr' doesn't match expected pattern '$expected_pattern'" | ||
| echo "Output:" | ||
| fail "$output" | ||
|
|
||
| echo "'$output'" | ||
| fi | ||
| } | ||
|
|
||
| assertPathNotExists "$nvimFolder/init.lua" | ||
|
|
||
| assertNeovimExpr "echo g:hmPluginVimlConfig" "HM_PLUGIN_VIML_CONFIG" | ||
| assertNeovimExpr "echo g:hmExtraConfig" "HM_EXTRA_CONFIG" | ||
| assertNeovimExpr "echo g:hmExtraConfig" "HM_EXTRA_CONFIG" | ||
| assertNeovimExpr "echo g:hmInitLua" "HM_INIT_LUA" | ||
| ''; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reusing
sideloadhere might seem tautological: if the name of the option was not clear, it wont help.I would suggest (feel free to change/improve I am not native):