2020-09-28 17:07:45 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.neovim;
|
|
|
|
|
|
|
|
runtime' = filter (f: f.enable) (attrValues cfg.runtime);
|
|
|
|
|
2021-08-03 10:59:48 +02:00
|
|
|
runtime = pkgs.linkFarm "neovim-runtime" (map (x: { name = x.target; path = x.source; }) runtime');
|
2020-09-28 17:07:45 +02:00
|
|
|
|
|
|
|
in {
|
|
|
|
options.programs.neovim = {
|
|
|
|
enable = mkEnableOption "Neovim";
|
|
|
|
|
|
|
|
defaultEditor = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-09-28 17:07:45 +02:00
|
|
|
When enabled, installs neovim and configures neovim to be the default editor
|
|
|
|
using the EDITOR environment variable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Symlink {command}`vi` to {command}`nvim` binary.
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Symlink {command}`vim` to {command}`nvim` binary.
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
withRuby = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Enable Ruby provider.";
|
2021-11-06 14:29:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
withPython3 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Enable Python 3 provider.";
|
2021-11-06 14:29:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
withNodeJs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Enable Node provider.";
|
2020-09-28 17:07:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
configure = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
customRC = '''
|
2020-09-28 17:07:45 +02:00
|
|
|
" here your custom configuration goes!
|
2021-10-03 18:06:03 +02:00
|
|
|
''';
|
|
|
|
packages.myVimPackage = with pkgs.vimPlugins; {
|
|
|
|
# loaded on launch
|
|
|
|
start = [ fugitive ];
|
|
|
|
# manually loadable by calling `:packadd $plugin-name`
|
|
|
|
opt = [ ];
|
2020-09-28 17:07:45 +02:00
|
|
|
};
|
2021-10-03 18:06:03 +02:00
|
|
|
}
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Generate your init file from your list of plugins and custom commands.
|
2022-08-03 01:57:59 +02:00
|
|
|
Neovim will then be wrapped to load <command>nvim -u /nix/store/«hash»-vimrc</command>
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.neovim-unwrapped";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "The package to use for the neovim binary.";
|
2020-09-28 17:07:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
description = "Resulting customized neovim package.";
|
|
|
|
};
|
|
|
|
|
|
|
|
runtime = mkOption {
|
|
|
|
default = {};
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
|
|
|
{ "ftplugin/c.vim".text = "setlocal omnifunc=v:lua.vim.lsp.omnifunc"; }
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Set of files that have to be linked in {file}`runtime`.
|
2020-09-28 17:07:45 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
type = with types; attrsOf (submodule (
|
|
|
|
{ name, config, ... }:
|
|
|
|
{ options = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-09-28 17:07:45 +02:00
|
|
|
Whether this /etc file should be generated. This
|
|
|
|
option allows specific /etc files to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
target = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-09-28 17:07:45 +02:00
|
|
|
Name of symlink. Defaults to the attribute
|
|
|
|
name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
text = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.lines;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Text of the file.";
|
2020-09-28 17:07:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
source = mkOption {
|
|
|
|
type = types.path;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Path of the source file.";
|
2020-09-28 17:07:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
target = mkDefault name;
|
|
|
|
source = mkIf (config.text != null) (
|
|
|
|
let name' = "neovim-runtime" + baseNameOf name;
|
|
|
|
in mkDefault (pkgs.writeText name' config.text));
|
|
|
|
};
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [
|
|
|
|
cfg.finalPackage
|
|
|
|
];
|
2021-10-28 18:51:44 +02:00
|
|
|
environment.variables.EDITOR = mkIf cfg.defaultEditor (mkOverride 900 "nvim");
|
2020-09-28 17:07:45 +02:00
|
|
|
|
|
|
|
programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
|
2021-11-06 14:29:01 +01:00
|
|
|
inherit (cfg) viAlias vimAlias withPython3 withNodeJs withRuby;
|
2020-09-28 17:07:45 +02:00
|
|
|
configure = cfg.configure // {
|
|
|
|
|
|
|
|
customRC = (cfg.configure.customRC or "") + ''
|
|
|
|
set runtimepath^=${runtime}/etc
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|