mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
neovim: Support configuring plugins using Fennel
PR #2637 added a 'type' field denoting the language used to configure neovim plugins. However, when the type is set to "fennel" or "teal" the configuration is silently ignored. This commit enables support for Fennel by transpiling it to Lua before appending the generated code to `init.lua`. This commit __does not__ provide spport for configs written in Teal; they are still silently ignored.
This commit is contained in:
committed by
Matthieu Coudron
parent
b5e86c1b19
commit
4625f26228
@@ -21,7 +21,7 @@ let
|
||||
|
||||
inherit
|
||||
(
|
||||
(import ../lib/file-type.nix {
|
||||
(import ../../lib/file-type.nix {
|
||||
inherit (config.home) homeDirectory;
|
||||
inherit lib pkgs;
|
||||
})
|
||||
@@ -50,6 +50,7 @@ in
|
||||
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||
|
||||
imports = [
|
||||
./fennel.nix
|
||||
(lib.mkRenamedOptionModule
|
||||
[ "programs" "neovim" "extraLuaConfig" ]
|
||||
[ "programs" "neovim" "initLua" ]
|
||||
40
modules/programs/neovim/fennel.nix
Normal file
40
modules/programs/neovim/fennel.nix
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.programs.neovim;
|
||||
in
|
||||
{
|
||||
config = lib.mkIf cfg.enable {
|
||||
programs.neovim.initLua =
|
||||
lib.mkIf (lib.hasAttr "fennel" cfg.generatedConfigs && cfg.generatedConfigs.fennel != "")
|
||||
(
|
||||
lib.mkAfter ''
|
||||
-- user-associated fennel plugin config {{{
|
||||
require('fennel-plugins')
|
||||
-- }}}
|
||||
''
|
||||
);
|
||||
|
||||
xdg.configFile."nvim/lua/fennel-plugins.lua" =
|
||||
let
|
||||
compiledFennel =
|
||||
pkgs.runCommand "fennel-plugins.lua"
|
||||
{
|
||||
fnlSrc = cfg.generatedConfigs.fennel;
|
||||
__structuredAttrs = true;
|
||||
}
|
||||
''
|
||||
${lib.getExe pkgs.jq} -rj '.fnlSrc' "$NIX_ATTRS_JSON_FILE" > fnlSrc
|
||||
${lib.getExe cfg.package.lua.pkgs.fennel} --compile fnlSrc > "$out"
|
||||
'';
|
||||
in
|
||||
lib.mkIf (lib.hasAttr "fennel" cfg.generatedConfigs && cfg.generatedConfigs.fennel != "") {
|
||||
source = compiledFennel;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -9,4 +9,5 @@
|
||||
neovim-extra-lua-default = ./extra-lua-default.nix;
|
||||
neovim-extra-lua-empty-plugin = ./extra-lua-empty-plugin.nix;
|
||||
neovim-plugin-type-warning = ./plugin-type-warning.nix;
|
||||
neovim-fennel-plugin-config = ./plugin-fennel-config.nix;
|
||||
}
|
||||
|
||||
36
tests/modules/programs/neovim/plugin-fennel-config.nix
Normal file
36
tests/modules/programs/neovim/plugin-fennel-config.nix
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
realPkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
lib.mkIf config.test.enableBig {
|
||||
programs.neovim = {
|
||||
enable = true;
|
||||
withRuby = false;
|
||||
plugins = with pkgs.vimPlugins; [
|
||||
{
|
||||
plugin = vim-nix;
|
||||
type = "fennel";
|
||||
config = ''(vim.cmd "let g:hmFennelPlugin='HM_FENNEL_PLUGIN'")'';
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
_module.args.pkgs = lib.mkForce realPkgs;
|
||||
|
||||
nmt.script = ''
|
||||
export PATH="$TESTED/home-path/bin:$PATH"
|
||||
export HOME=$TMPDIR/hm-user
|
||||
export XDG_CONFIG_HOME="$TESTED/home-files/.config"
|
||||
initLua="$TESTED/home-files/.config/nvim/init.lua"
|
||||
|
||||
assertFileContains "$initLua" "require('fennel-plugins')"
|
||||
|
||||
vimout=$(mktemp)
|
||||
nvim --headless +'lua print(vim.g.hmFennelPlugin)' +q! 2&> $vimout
|
||||
assertFileContains "$vimout" "HM_FENNEL_PLUGIN"
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user