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:
Kelton Bassingthwaite
2026-04-14 18:36:37 -07:00
committed by Matthieu Coudron
parent b5e86c1b19
commit 4625f26228
4 changed files with 79 additions and 1 deletions

View File

@@ -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" ]

View 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;
};
};
}

View File

@@ -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;
}

View 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"
'';
}