Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
669baa7
neovim: remove wrapper's luaRcContent from init.lua and load via args
veselyn Apr 3, 2026
50b090d
revert: "neovim: remove wrapper's luaRcContent from init.lua and load…
veselyn Apr 6, 2026
f970836
neovim: expose wrapGeneratedConfigs option to control how generated c…
veselyn Apr 6, 2026
001e4fb
neovim: use false as option variant to disable wrapping
veselyn Apr 6, 2026
c97e7c8
Merge remote-tracking branch 'upstream/master' into move-luaRcContent…
veselyn Apr 7, 2026
56fadc9
neovim: replace wrapGeneratedConfigs with sideloadInitLua option
veselyn Apr 7, 2026
01fe9de
neovim: make wrapper-args test pass
veselyn Apr 8, 2026
93a8afb
neovim: make no-init-vim test strictly about init.vim
veselyn Apr 8, 2026
cf275d0
neovim: test enabled sideloadInitLua option
veselyn Apr 8, 2026
dc06681
neovim: make existing extra-lua-* tests pass
veselyn Apr 8, 2026
e60886d
neovim: format module
veselyn Apr 8, 2026
f82ea7b
Merge remote-tracking branch 'upstream/master' into move-luaRcContent…
veselyn Apr 8, 2026
c353b71
neovim: attempt to fix test on CI by using realPkgs.neovim-unwrapped
veselyn Apr 8, 2026
e79600c
neovim: update test snapshots after merging upstream
veselyn Apr 8, 2026
5775343
neovim: format tests
veselyn Apr 8, 2026
70c96ef
Merge remote-tracking branch 'upstream/master' into move-luaRcContent…
veselyn Apr 17, 2026
246ca77
neovim: improve sideloadInitLua option description
veselyn Apr 17, 2026
11579ca
neovim: revert tests
veselyn Apr 17, 2026
74d746d
neovim: assert init.lua doesn't exist when sideloadInitLua is true
veselyn Apr 17, 2026
2e50c31
neovim: update init.lua snapshots with disabled ruby provider
veselyn Apr 17, 2026
dbf2358
news: add entry about programs.neovim and sideloaded init.lua
veselyn Apr 17, 2026
b56ca35
neovim: reference correct full path to init.lua
veselyn Apr 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/misc/news/2026/04/2026-04-17_17-00-13.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ config, ... }:
{
time = "2026-04-17T15:00:13+00:00";
condition = config.programs.neovim.enable;
message = ''
The module `programs.neovim` now writes to
{file}`$XDG_CONFIG_HOME/nvim/init.lua` by default.

Comment thread
khaneliman marked this conversation as resolved.
If you want to manage {file}`$XDG_CONFIG_HOME/nvim/init.lua` yourself, you
can set {option}`programs.neovim.sideloadInitLua` to `true` to load the
content of {option}`programs.neovim.initLua` through neovim wrapper
arguments instead.
'';
}
27 changes: 17 additions & 10 deletions modules/programs/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ in
'';
};

sideloadInitLua = mkOption {
type = types.bool;
default = false;
description = ''
Enable to avoid writing the content of {var}`initLua` to the default
location {file}`$XDG_CONFIG_HOME/nvim/init.lua` and load it through
neovim wrapper arguments instead.


This is useful if you want to manage your own {file}`init.lua` imperatively.
'';
};

initLua = mkOption {
type = types.lines;
default = "";
Expand Down Expand Up @@ -531,13 +544,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
{
warnings = legacyPluginTypeWarnings;
Expand Down Expand Up @@ -568,9 +574,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 =
Expand All @@ -588,7 +594,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
))
Expand All @@ -615,6 +621,7 @@ in
++ [
{
"nvim/init.lua" = mkIf (cfg.initLua != "") {
enable = !cfg.sideloadInitLua;
text = cfg.initLua;
Comment thread
veselyn marked this conversation as resolved.
};

Expand Down
3 changes: 1 addition & 2 deletions tests/modules/programs/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
neovim-runtime = ./runtime.nix;
neovim-wrapper-args = ./wrapper-args.nix;

# waiting for a nixpkgs patch
neovim-no-init-vim = ./no-init.nix;
neovim-no-init-lua = ./no-init-lua.nix;
neovim-extra-lua-init = ./extra-lua-init.nix;
neovim-extra-lua-default = ./extra-lua-default.nix;
neovim-extra-lua-empty-plugin = ./extra-lua-empty-plugin.nix;
Expand Down
10 changes: 9 additions & 1 deletion tests/modules/programs/neovim/extra-lua-default.nix
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'
''
)}
'';
}
11 changes: 9 additions & 2 deletions tests/modules/programs/neovim/extra-lua-empty-plugin.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, lib, ... }:
{
imports = [ ./stubs.nix ];

Expand All @@ -13,7 +13,14 @@
};

nmt.script = ''
nvimFolder="home-files/.config/nvim"
initLua="home-files/.config/nvim/init.lua"
assertPathNotExists "$initLua"
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'
''
)}
'';
}
1 change: 1 addition & 0 deletions tests/modules/programs/neovim/extra-lua-init.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
initLuaNormalized="$(normalizeStorePaths "$initLua")"

assertFileContent "$initLuaNormalized" ${builtins.toFile "init.lua-expected" ''
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'
-- initLua
''}
'';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
withPython3 = true;
withRuby = false;

sideloadInitLua = true;

extraPython3Packages = (
ps: with ps; [
jedi
Expand All @@ -22,6 +24,10 @@
vim-fugitive
{ plugin = vim-sensible; }
];

initLua = ''
-- initLua
'';
};
nmt.script = ''
nvimFolder="home-files/.config/nvim"
Expand Down
5 changes: 4 additions & 1 deletion tests/modules/programs/neovim/wrapper-args.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ in
nvimBin="home-path/bin/nvim"
export PATH="$TESTED/home-path/bin:$PATH"
export HOME="$TMPDIR/hm-user"
# Load init.lua from $XDG_CONFIG_HOME/nvim/init.lua
export XDG_CONFIG_HOME="$TESTED/home-files/.config"

assertBinaryContains() {
local file="$TESTED/$1"
Expand All @@ -55,7 +57,8 @@ in
assertNeovimExpr() {
local var_name="$1"
local expected_pattern="$2"
local output=$(nvim -i NONE --headless --cmd "echo $var_name" +q! 2>&1)
# Use -c to evaluate the expression after init.lua is loaded
local output=$(nvim -i NONE --headless -c "echo $var_name" +q! 2>&1)
local exit_code=$?

if [ $exit_code -ne 0 ]; then
Expand Down
Loading