2023-04-20 22:41:37 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-02-09 21:20:07 +01:00
|
|
|
with lib; {
|
2023-04-20 22:41:37 +02:00
|
|
|
options = {
|
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2023-09-18 21:38:58 +07:00
|
|
|
Symlink `vi` to `nvim` binary.
|
2023-04-20 22:41:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2023-09-18 21:38:58 +07:00
|
|
|
Symlink `vim` to `nvim` binary.
|
2023-04-20 22:41:37 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "Neovim to use for NixVim.";
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
wrapRc = mkOption {
|
|
|
|
type = types.bool;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "Should the config be included in the wrapper script.";
|
2023-04-20 22:41:37 +02:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "Wrapped Neovim.";
|
2023-04-20 22:41:37 +02:00
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
|
2023-12-07 13:40:40 +01:00
|
|
|
initPath = mkOption {
|
|
|
|
type = types.str;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "The path to the `init.lua` file.";
|
2023-12-07 13:40:40 +01:00
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
initContent = mkOption {
|
|
|
|
type = types.str;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "The content of the `init.lua` file.";
|
2023-04-20 22:41:37 +02:00
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
2023-12-07 13:40:40 +01:00
|
|
|
|
|
|
|
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.";
|
2023-12-07 13:40:40 +01:00
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
2023-04-20 22:41:37 +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 ({
|
2024-01-06 19:17:32 +01:00
|
|
|
inherit
|
|
|
|
(config)
|
2024-01-06 14:59:00 -05:00
|
|
|
extraPython3Packages
|
2024-01-06 19:17:32 +01:00
|
|
|
viAlias
|
|
|
|
vimAlias
|
|
|
|
;
|
2023-04-20 22:41:37 +02:00
|
|
|
# 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 = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
customRC =
|
|
|
|
''
|
|
|
|
vim.cmd([[
|
|
|
|
${neovimConfig.neovimRcContent}
|
|
|
|
]])
|
|
|
|
''
|
|
|
|
+ config.content;
|
|
|
|
|
2023-12-07 13:40:40 +01:00
|
|
|
init = pkgs.writeText "init.lua" customRC;
|
|
|
|
initPath = toString init;
|
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
extraWrapperArgs = builtins.concatStringsSep " " (
|
|
|
|
(optional (config.extraPackages != [])
|
|
|
|
''--prefix PATH : "${makeBinPath config.extraPackages}"'')
|
2023-05-22 15:45:47 +05:30
|
|
|
++ (optional config.wrapRc
|
2023-12-07 13:40:40 +01:00
|
|
|
''--add-flags -u --add-flags "${init}"'')
|
2023-04-20 22:41:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (neovimConfig
|
|
|
|
// {
|
|
|
|
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;
|
|
|
|
wrapRc = false;
|
|
|
|
});
|
|
|
|
in {
|
|
|
|
type = lib.mkForce "lua";
|
|
|
|
finalPackage = wrappedNeovim;
|
|
|
|
initContent = customRC;
|
2023-12-07 13:40:40 +01:00
|
|
|
inherit initPath;
|
|
|
|
|
|
|
|
printInitPackage = pkgs.writeShellApplication {
|
|
|
|
name = "nixvim-print-init";
|
|
|
|
runtimeInputs = with pkgs; [stylua bat];
|
|
|
|
text = ''
|
|
|
|
stylua - <"${initPath}" | bat --language=lua
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-02 10:50:24 +01:00
|
|
|
extraConfigLuaPre = lib.optionalString config.wrapRc ''
|
|
|
|
-- Ignore the user lua configuration
|
2024-01-03 22:24:59 +01:00
|
|
|
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-01-02 10:50:24 +01:00
|
|
|
'';
|
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
extraPlugins =
|
|
|
|
if config.wrapRc
|
|
|
|
then [config.filesPlugin]
|
|
|
|
else [];
|
|
|
|
};
|
|
|
|
}
|