2020-10-07 09:15:18 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.neovim;
|
2023-04-29 16:46:19 +00:00
|
|
|
in
|
|
|
|
{
|
2020-10-07 09:15:18 +00:00
|
|
|
options.programs.neovim = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-10-21 18:38:19 +00:00
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-10-21 18:38:19 +00:00
|
|
|
Whether to enable Neovim.
|
|
|
|
|
|
|
|
When enabled through this option, Neovim is wrapped to use a
|
|
|
|
configuration managed by this module. The configuration file in the
|
|
|
|
user's home directory at {file}`~/.config/nvim/init.vim` is no longer
|
|
|
|
loaded by default.
|
|
|
|
'';
|
|
|
|
};
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
defaultEditor = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-10-07 09:15:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-10-07 09:15:18 +00:00
|
|
|
When enabled, installs neovim and configures neovim to be the default editor
|
|
|
|
using the EDITOR environment variable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
viAlias = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-10-07 09:15:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Symlink {command}`vi` to {command}`nvim` binary.
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
vimAlias = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-10-07 09:15:18 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Symlink {command}`vim` to {command}`nvim` binary.
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
withRuby = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-10-07 09:15:18 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable Ruby provider.";
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
withPython3 = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable Python 3 provider.";
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
withNodeJs = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-12-06 16:07:01 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable Node provider.";
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
configure = lib.mkOption {
|
|
|
|
type = lib.types.attrs;
|
2023-04-29 16:46:19 +00:00
|
|
|
default = { };
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''
|
2021-10-06 13:57:05 +00:00
|
|
|
{
|
|
|
|
customRC = '''
|
2020-10-07 09:15:18 +00:00
|
|
|
" here your custom configuration goes!
|
2021-10-06 13:57:05 +00:00
|
|
|
''';
|
|
|
|
packages.myVimPackage = with pkgs.vimPlugins; {
|
|
|
|
# loaded on launch
|
|
|
|
start = [ fugitive ];
|
|
|
|
# manually loadable by calling `:packadd $plugin-name`
|
|
|
|
opt = [ ];
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
2021-10-06 13:57:05 +00:00
|
|
|
}
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-10-07 09:15:18 +00:00
|
|
|
Generate your init file from your list of plugins and custom commands.
|
2022-08-12 12:06:08 +00:00
|
|
|
Neovim will then be wrapped to load {command}`nvim -u /nix/store/«hash»-vimrc`
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
package = lib.mkPackageOption pkgs "neovim-unwrapped" { };
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
finalPackage = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
2020-10-07 09:15:18 +00:00
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Resulting customized neovim package.";
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
runtime = lib.mkOption {
|
2023-04-29 16:46:19 +00:00
|
|
|
default = { };
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''
|
2021-10-06 13:57:05 +00:00
|
|
|
{ "ftplugin/c.vim".text = "setlocal omnifunc=v:lua.vim.lsp.omnifunc"; }
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Set of files that have to be linked in {file}`runtime`.
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
type = with lib.types; attrsOf (submodule (
|
2020-10-07 09:15:18 +00:00
|
|
|
{ name, config, ... }:
|
2023-04-29 16:46:19 +00:00
|
|
|
{
|
|
|
|
options = {
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-10-07 09:15:18 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-04-29 16:46:19 +00:00
|
|
|
Whether this runtime directory should be generated. This
|
|
|
|
option allows specific runtime files to be disabled.
|
2020-10-07 09:15:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
target = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-10-07 09:15:18 +00:00
|
|
|
Name of symlink. Defaults to the attribute
|
|
|
|
name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
text = lib.mkOption {
|
2020-10-07 09:15:18 +00:00
|
|
|
default = null;
|
2024-05-15 15:35:15 +00:00
|
|
|
type = lib.types.nullOr lib.types.lines;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Text of the file.";
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
source = lib.mkOption {
|
2023-05-24 13:37:59 +00:00
|
|
|
default = null;
|
2024-05-15 15:35:15 +00:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Path of the source file.";
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config.target = lib.mkDefault name;
|
2023-04-29 16:46:19 +00:00
|
|
|
}
|
|
|
|
));
|
2020-10-07 09:15:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-10-07 09:15:18 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
cfg.finalPackage
|
|
|
|
];
|
2024-05-15 15:35:15 +00:00
|
|
|
environment.variables.EDITOR = lib.mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
|
2024-07-27 06:49:29 +00:00
|
|
|
# On most NixOS configurations /share is already included, so it includes
|
|
|
|
# this directory as well. But This makes sure that /share/nvim/site paths
|
|
|
|
# from other packages will be used by neovim.
|
|
|
|
environment.pathsToLink = [ "/share/nvim" ];
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
environment.etc = builtins.listToAttrs (builtins.attrValues (builtins.mapAttrs
|
2023-04-29 16:46:19 +00:00
|
|
|
(name: value: {
|
|
|
|
name = "xdg/nvim/${name}";
|
2024-05-15 15:35:15 +00:00
|
|
|
value = builtins.removeAttrs
|
2023-05-24 13:37:59 +00:00
|
|
|
(value // {
|
|
|
|
target = "xdg/nvim/${value.target}";
|
|
|
|
})
|
2024-05-15 15:35:15 +00:00
|
|
|
(lib.optionals (builtins.isNull value.source) [ "source" ]);
|
2023-04-29 16:46:19 +00:00
|
|
|
})
|
|
|
|
cfg.runtime));
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
|
|
|
|
inherit (cfg) viAlias vimAlias withPython3 withNodeJs withRuby configure;
|
2020-10-07 09:15:18 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|