2023-04-20 22:41:37 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
2024-04-13 08:40:47 +01:00
|
|
|
helpers,
|
2023-04-20 22:41:37 +02:00
|
|
|
...
|
|
|
|
}:
|
2024-07-07 18:50:30 +03:00
|
|
|
let
|
2024-09-03 13:54:21 +01:00
|
|
|
inherit (lib) types mkOption mkPackageOption;
|
2024-10-13 09:33:20 +03:00
|
|
|
inherit (lib) optional optionalAttrs;
|
2024-09-12 14:56:36 +01:00
|
|
|
builders = lib.nixvim.builders.withPkgs pkgs;
|
2024-12-22 12:23:27 +00:00
|
|
|
inherit (pkgs.stdenv.hostPlatform) system;
|
2024-07-07 18:50:30 +03:00
|
|
|
in
|
2024-02-09 21:20:07 +01:00
|
|
|
{
|
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
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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.";
|
|
|
|
};
|
|
|
|
|
2024-11-13 15:19:35 -03:00
|
|
|
withPerl = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable Perl provider.";
|
|
|
|
};
|
|
|
|
|
2024-11-13 15:23:33 -03:00
|
|
|
withPython3 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Enable Python 3 provider.";
|
|
|
|
};
|
|
|
|
|
2024-09-03 13:54:21 +01:00
|
|
|
package = mkPackageOption pkgs "Neovim" {
|
|
|
|
default = "neovim-unwrapped";
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
wrapRc = mkOption {
|
|
|
|
type = types.bool;
|
2024-09-25 17:38:23 +01:00
|
|
|
description = ''
|
|
|
|
Whether the config will be included in the wrapper script.
|
|
|
|
|
|
|
|
When enabled, the nixvim config will be passed to `nvim` using the `-u` option.
|
|
|
|
'';
|
|
|
|
defaultText = lib.literalMD ''
|
|
|
|
Configured by your installation method: `false` when using the home-manager module, `true` otherwise.
|
|
|
|
'';
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
|
2024-09-25 17:43:04 +01:00
|
|
|
impureRtp = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to keep the (impure) nvim config directory in the runtimepath.
|
|
|
|
|
|
|
|
If disabled, the XDG config dirs `nvim` and `nvim/after` will be removed from the runtimepath.
|
|
|
|
'';
|
|
|
|
defaultText = lib.literalMD ''
|
|
|
|
Configured by your installation method: `true` when using the home-manager module, `false` otherwise.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
build = {
|
|
|
|
# TODO: `standalonePackage`; i.e. package + printInitPackage + man-docs bundled together
|
2023-04-20 22:41:37 +02:00
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2024-09-24 07:02:22 +01:00
|
|
|
description = ''
|
|
|
|
Wrapped Neovim.
|
|
|
|
|
|
|
|
> [!NOTE]
|
|
|
|
> Evaluating this option will also check `assertions` and print any `warnings`.
|
|
|
|
> If this is not desired, you can use `build.packageUnchecked` instead.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
defaultText = lib.literalExpression "config.build.packageUnchecked";
|
|
|
|
apply =
|
|
|
|
let
|
|
|
|
assertions = builtins.concatMap (x: lib.optional (!x.assertion) x.message) config.assertions;
|
|
|
|
in
|
|
|
|
if assertions != [ ] then
|
|
|
|
throw "\nFailed assertions:\n${lib.concatMapStringsSep "\n" (msg: "- ${msg}") assertions}"
|
|
|
|
else
|
|
|
|
lib.showWarnings config.warnings;
|
|
|
|
};
|
|
|
|
|
|
|
|
packageUnchecked = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = ''
|
|
|
|
Wrapped Neovim (without checking warnings or assertions).
|
|
|
|
'';
|
2024-09-24 07:02:22 +01:00
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
|
2025-01-20 13:50:50 +00:00
|
|
|
nvimPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = ''
|
|
|
|
Wrapped Neovim (without man-docs, printInitPackage, etc).
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
initFile = mkOption {
|
|
|
|
type = types.path;
|
2024-09-24 07:21:25 +01:00
|
|
|
description = ''
|
|
|
|
The generated `init.lua` file.
|
|
|
|
|
|
|
|
> [!NOTE]
|
|
|
|
> If `performance.byteCompileLua` is enabled, this file may not contain human-readable lua source code.
|
|
|
|
> Consider using `build.initSource` instead.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
initSource = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
The generated `init.lua` source file.
|
|
|
|
|
|
|
|
This is usually identical to `build.initFile`, however if `performance.byteCompileLua` is enabled,
|
|
|
|
this option will refer to the un-compiled lua source file.
|
|
|
|
'';
|
2024-09-24 07:02:22 +01:00
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
2023-12-07 13:40:40 +01:00
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
printInitPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = ''
|
|
|
|
A tool to show the content of the generated `init.lua` file.
|
|
|
|
Run using `${config.build.printInitPackage.meta.mainProgram}`.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
2024-12-22 12:23:27 +00:00
|
|
|
|
|
|
|
manDocsPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
defaultText = lib.literalMD "`packages.<system>.man-docs` from Nixvim's flake";
|
|
|
|
description = ''
|
|
|
|
Nixvim's manpage documentation.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
};
|
2023-12-07 13:40:40 +01:00
|
|
|
};
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
2025-05-03 18:25:49 +03:00
|
|
|
# Optionally byte compile lua library
|
|
|
|
extraLuaPackages =
|
|
|
|
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.luaLib then
|
|
|
|
ps: map builders.byteCompileLuaDrv (config.extraLuaPackages ps)
|
|
|
|
else
|
|
|
|
config.extraLuaPackages;
|
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
|
|
|
|
{
|
2025-05-03 18:25:49 +03:00
|
|
|
inherit extraLuaPackages;
|
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
|
2024-05-07 09:45:32 +02:00
|
|
|
withRuby
|
2024-03-04 05:59:53 +08:00
|
|
|
withNodeJs
|
2024-11-13 15:19:35 -03:00
|
|
|
withPerl
|
2024-11-13 15:23:33 -03:00
|
|
|
withPython3
|
2024-01-06 19:17:32 +01:00
|
|
|
;
|
2023-04-20 22:41:37 +02:00
|
|
|
# inherit customRC;
|
2025-03-31 23:47:06 +02:00
|
|
|
inherit (config.build) plugins;
|
2023-04-20 22:41:37 +02:00
|
|
|
}
|
|
|
|
# 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
|
2024-07-07 18:50:30 +03:00
|
|
|
// optionalAttrs (lib.functionArgs pkgs.neovimUtils.makeNeovimConfig ? configure) {
|
2023-04-20 22:41:37 +02:00
|
|
|
configure.packages = {
|
|
|
|
nixvim = {
|
2025-03-31 23:47:06 +02:00
|
|
|
start = map (x: x.plugin) config.build.plugins;
|
2023-04-20 22:41:37 +02:00
|
|
|
opt = [ ];
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2024-05-05 19:39:35 +02:00
|
|
|
|
2025-01-20 13:50:50 +00:00
|
|
|
wrappedNeovim = pkgs.wrapNeovimUnstable package neovimConfig;
|
2024-10-13 09:54:05 +03:00
|
|
|
|
2024-07-21 11:55:52 +03:00
|
|
|
customRC = helpers.concatNonEmptyLines [
|
2025-01-20 13:50:50 +00:00
|
|
|
(helpers.wrapVimscriptForLua wrappedNeovim.initRc)
|
2024-07-21 11:55:52 +03:00
|
|
|
config.content
|
|
|
|
];
|
2024-05-05 19:39:35 +02:00
|
|
|
|
2024-09-24 07:21:25 +01:00
|
|
|
initSource = builders.writeLua "init.lua" customRC;
|
|
|
|
initByteCompiled = builders.writeByteCompiledLua "init.lua" customRC;
|
2024-09-24 07:02:22 +01:00
|
|
|
initFile =
|
2024-07-25 13:25:13 +03:00
|
|
|
if
|
|
|
|
config.type == "lua"
|
|
|
|
&& config.performance.byteCompileLua.enable
|
|
|
|
&& config.performance.byteCompileLua.initLua
|
|
|
|
then
|
2024-09-24 07:21:25 +01:00
|
|
|
initByteCompiled
|
2024-07-25 13:25:13 +03:00
|
|
|
else
|
2024-09-24 07:21:25 +01:00
|
|
|
initSource;
|
2024-05-05 19:39:35 +02:00
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
extraWrapperArgs = builtins.concatStringsSep " " (
|
2025-03-23 12:27:50 +01:00
|
|
|
# Setting environment variables in the wrapper
|
|
|
|
(lib.mapAttrsToList (
|
|
|
|
name: value:
|
|
|
|
lib.escapeShellArgs [
|
|
|
|
"--set"
|
|
|
|
name
|
|
|
|
value
|
|
|
|
]
|
|
|
|
) config.env)
|
|
|
|
++ (optional (
|
2024-07-07 18:50:30 +03:00
|
|
|
config.extraPackages != [ ]
|
|
|
|
) ''--prefix PATH : "${lib.makeBinPath config.extraPackages}"'')
|
2024-09-24 07:02:22 +01:00
|
|
|
++ (optional config.wrapRc ''--add-flags -u --add-flags "${initFile}"'')
|
2023-04-20 22:41:37 +02:00
|
|
|
);
|
2024-05-05 19:39:35 +02:00
|
|
|
|
2024-07-17 22:26:06 +03:00
|
|
|
package =
|
|
|
|
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.nvimRuntime then
|
|
|
|
# Using symlinkJoin to avoid rebuilding neovim
|
|
|
|
pkgs.symlinkJoin {
|
|
|
|
name = "neovim-byte-compiled-${lib.getVersion config.package}";
|
|
|
|
paths = [ config.package ];
|
|
|
|
# Required attributes from original neovim package
|
2024-08-15 22:28:28 -05:00
|
|
|
inherit (config.package) lua meta;
|
2024-09-12 14:56:36 +01:00
|
|
|
nativeBuildInputs = [ builders.byteCompileLuaHook ];
|
2024-07-17 22:26:06 +03:00
|
|
|
postBuild = ''
|
|
|
|
# Replace Nvim's binary symlink with a regular file,
|
|
|
|
# or Nvim will use original runtime directory
|
|
|
|
rm $out/bin/nvim
|
|
|
|
cp ${config.package}/bin/nvim $out/bin/nvim
|
|
|
|
|
|
|
|
runHook postFixup
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
config.package;
|
2023-04-20 22:41:37 +02:00
|
|
|
in
|
|
|
|
{
|
2024-09-24 07:02:22 +01:00
|
|
|
build = {
|
2024-09-24 07:21:25 +01:00
|
|
|
inherit initFile initSource;
|
2025-01-20 13:50:50 +00:00
|
|
|
package = config.build.packageUnchecked;
|
|
|
|
|
|
|
|
nvimPackage = wrappedNeovim.override (prev: {
|
|
|
|
wrapperArgs =
|
|
|
|
(if lib.isString prev.wrapperArgs then prev.wrapperArgs else lib.escapeShellArgs prev.wrapperArgs)
|
|
|
|
+ " "
|
|
|
|
+ extraWrapperArgs;
|
|
|
|
wrapRc = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
packageUnchecked = pkgs.symlinkJoin {
|
|
|
|
name = "nixvim";
|
|
|
|
paths =
|
|
|
|
with config.build;
|
|
|
|
[
|
|
|
|
nvimPackage
|
|
|
|
printInitPackage
|
|
|
|
]
|
|
|
|
++ lib.optionals config.enableMan [
|
|
|
|
manDocsPackage
|
|
|
|
];
|
|
|
|
meta.mainProgram = "nvim";
|
|
|
|
};
|
2024-09-24 07:02:22 +01:00
|
|
|
|
|
|
|
printInitPackage = pkgs.writeShellApplication {
|
|
|
|
name = "nixvim-print-init";
|
|
|
|
runtimeInputs = [ pkgs.bat ];
|
2024-09-24 07:21:25 +01:00
|
|
|
runtimeEnv = {
|
|
|
|
init = config.build.initSource;
|
|
|
|
};
|
2024-09-24 07:02:22 +01:00
|
|
|
text = ''
|
2024-09-24 07:21:25 +01:00
|
|
|
bat --language=lua "$init"
|
2024-09-24 07:02:22 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-12-22 12:23:27 +00:00
|
|
|
|
|
|
|
manDocsPackage = config.flake.packages.${system}.man-docs;
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
|
|
|
|
2024-09-25 17:43:04 +01:00
|
|
|
# Set `wrapRc` and `impureRtp`s option defaults with even lower priority than `mkOptionDefault`
|
2024-09-25 17:38:23 +01:00
|
|
|
wrapRc = lib.mkOverride 1501 true;
|
2024-09-25 17:43:04 +01:00
|
|
|
impureRtp = lib.mkOverride 1501 false;
|
2024-09-25 17:38:23 +01:00
|
|
|
|
2024-08-21 10:52:35 -05:00
|
|
|
extraConfigLuaPre = lib.mkOrder 100 (
|
2024-09-25 17:38:23 +01:00
|
|
|
lib.concatStringsSep "\n" (
|
2024-09-25 17:43:04 +01:00
|
|
|
lib.optional (!config.impureRtp) ''
|
2024-09-25 17:38:23 +01:00
|
|
|
-- 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
|
|
|
|
''
|
|
|
|
# Add a global table at start of init
|
|
|
|
++ lib.singleton ''
|
|
|
|
-- Nixvim's internal module table
|
|
|
|
-- Can be used to share code throughout init.lua
|
|
|
|
local _M = {}
|
|
|
|
''
|
|
|
|
)
|
2024-08-21 10:52:35 -05:00
|
|
|
);
|
2023-12-07 13:40:40 +01:00
|
|
|
|
2024-09-24 07:02:22 +01:00
|
|
|
extraPlugins = lib.mkIf config.wrapRc [ config.build.extraFiles ];
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
}
|