nix-community.nixvim/wrappers/modules/output.nix

167 lines
4.1 KiB
Nix
Raw Normal View History

{
pkgs,
config,
lib,
2024-04-13 08:40:47 +01:00
helpers,
...
}:
2024-05-05 19:39:35 +02:00
with lib;
{
options = {
viAlias = mkOption {
type = types.bool;
default = false;
description = ''
Symlink `vi` to `nvim` binary.
'';
};
vimAlias = mkOption {
type = types.bool;
default = false;
description = ''
Symlink `vim` to `nvim` binary.
'';
};
2024-05-07 09:45:32 +02:00
withRuby = mkOption {
type = types.bool;
default = true;
description = "Enable Ruby provider.";
};
2024-03-04 05:59:53 +08:00
withNodeJs = mkOption {
type = types.bool;
default = false;
description = "Enable Node provider.";
};
package = mkOption {
type = types.package;
default = pkgs.neovim-unwrapped;
2024-02-11 12:51:34 +00:00
description = "Neovim to use for NixVim.";
};
wrapRc = mkOption {
type = types.bool;
2024-02-11 12:51:34 +00:00
description = "Should the config be included in the wrapper script.";
default = false;
};
finalPackage = mkOption {
type = types.package;
2024-02-11 12:51:34 +00:00
description = "Wrapped Neovim.";
readOnly = true;
};
initPath = mkOption {
type = types.str;
2024-02-11 12:51:34 +00:00
description = "The path to the `init.lua` file.";
readOnly = true;
visible = false;
};
initContent = mkOption {
type = types.str;
2024-02-11 12:51:34 +00:00
description = "The content of the `init.lua` file.";
readOnly = true;
visible = false;
};
printInitPackage = mkOption {
type = types.package;
2024-02-11 12:51:34 +00:00
description = "A tool to show the content of the generated `init.lua` file.";
readOnly = true;
visible = false;
};
};
2024-05-05 19:39:35 +02:00
config =
let
defaultPlugin = {
plugin = null;
config = "";
optional = false;
};
normalizedPlugins = map (
x: defaultPlugin // (if x ? plugin then x else { plugin = x; })
) config.extraPlugins;
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
{
inherit (config)
extraPython3Packages
viAlias
vimAlias
2024-05-07 09:45:32 +02:00
withRuby
2024-05-05 19:39:35 +02:00
withNodeJs
;
# inherit customRC;
plugins = normalizedPlugins;
}
# Necessary to make sure the runtime path is set properly in NixOS 22.05,
# or more generally before the commit:
# cda1f8ae468 - neovim: pass packpath via the wrapper
// optionalAttrs (functionArgs pkgs.neovimUtils.makeNeovimConfig ? configure) {
configure.packages = {
nixvim = {
start = map (x: x.plugin) normalizedPlugins;
opt = [ ];
};
};
2024-05-05 19:39:35 +02:00
}
);
customRC =
''
vim.cmd([[
${neovimConfig.neovimRcContent}
]])
''
+ config.content;
init = helpers.writeLua "init.lua" customRC;
initPath = toString init;
extraWrapperArgs = builtins.concatStringsSep " " (
(optional (config.extraPackages != [ ]) ''--prefix PATH : "${makeBinPath config.extraPackages}"'')
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
);
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
neovimConfig
// {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
wrapRc = false;
}
);
in
{
type = lib.mkForce "lua";
finalPackage = wrappedNeovim;
initContent = customRC;
inherit initPath;
printInitPackage = pkgs.writeShellApplication {
name = "nixvim-print-init";
runtimeInputs = with pkgs; [
stylua
bat
];
text = ''
stylua - <"${initPath}" | bat --language=lua
'';
};
extraConfigLuaPre = lib.optionalString config.wrapRc ''
-- Ignore the user lua configuration
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- ~/.config/nvim
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after
vim.opt.runtimepath:remove(vim.fn.stdpath('data') .. "/site") -- ~/.local/share/nvim/site
'';
2024-05-05 19:39:35 +02:00
extraPlugins = if config.wrapRc then [ config.filesPlugin ] else [ ];
};
}