Skip to content

Commit

Permalink
programs.neovim: add extraLuaConfig (nix-community#3639)
Browse files Browse the repository at this point in the history
* programs.neovim: add extraLuaConfig

Add a configuration option to add custom lua configuration lines to
`lua.init`.

* apply review: formatting

* apply review: fix test
  • Loading branch information
GuillaumeDesforges authored and 15cm committed Feb 9, 2023
1 parent 1333c39 commit a110c1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/programs/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ in {
'';
};

extraLuaConfig = mkOption {
type = types.lines;
default = "";
example = ''
vim.opt.nobackup = true
'';
description = ''
Custom lua lines.
'';
};

extraPackages = mkOption {
type = with types; listOf package;
default = [ ];
Expand Down Expand Up @@ -394,7 +405,8 @@ in {
"vim.cmd [[source ${
pkgs.writeText "nvim-init-home-manager.vim"
neovimConfig.neovimRcContent
}]]" + lib.optionalString hasLuaConfig
}]]" + config.programs.neovim.extraLuaConfig
+ lib.optionalString hasLuaConfig
config.programs.neovim.generatedConfigs.lua;
in mkIf (luaRcContent != "") { text = luaRcContent; };

Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

# waiting for a nixpkgs patch
neovim-no-init = ./no-init.nix;
neovim-extra-lua-init = ./extra-lua-init.nix;
}
23 changes: 23 additions & 0 deletions tests/modules/programs/neovim/extra-lua-init.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ config, lib, pkgs, ... }:

with lib;

{
config = {
programs.neovim = {
enable = true;

extraLuaConfig = ''
-- extraLuaConfig
'';
};
nmt.script = ''
nvimFolder="home-files/.config/nvim"
assertFileContent "$nvimFolder/init.lua" ${
pkgs.writeText "init.lua-expected" ''
-- extraLuaConfig
''
}
'';
};
}

0 comments on commit a110c1c

Please sign in to comment.