plugins: do not import helpers.nix directly

This commit is contained in:
Gaetan Lepage 2024-02-09 14:31:04 +01:00 committed by Gaétan Lepage
parent 9f3bbca7f1
commit 7dbf7f978c
13 changed files with 83 additions and 119 deletions

View file

@ -29,43 +29,7 @@ Most of nixvim is dedicated to wrapping neovim plugin such that we can configure
To add a new plugin you need to do the following. To add a new plugin you need to do the following.
1. Add a file in the correct sub-directory of [plugins](plugins). This depends on your exact plugin. 1. Add a file in the correct sub-directory of [plugins](plugins). This depends on your exact plugin.
You will most certainly need the `helpers`, they can be added by doing something like: 2. Write the code for the corresponding nixvim module. You can start from the [template](plugins/TEMPLATE.nix).
```nix
{
lib,
pkgs,
...
} @ args:
let
helpers = import ../helpers.nix args;
in {
}
```
2. Create the minimal options for a new plugin (in `options.plugins.<plug-name>`:
- `enable = mkEnableOption ...` to toggle the plugin.
- `package = helpers.mkPackageOption ...` to change the package options.
3. Add the plugin package to the installed plugins if it is enabled. This can be done with the following:
```nix
{
config =
let
cfg = config.plugins."<plug-name>";
in lib.mkIf cfg.enable {
extraPlugins = [cfg.package];
extraConfigLua = ''
<plugin configuration if needed>
'';
};
}
```
You will then need to add Nix options for all (or most) of the upstream plugin options. You will then need to add Nix options for all (or most) of the upstream plugin options.
These options should be in `camelCase` (whereas most plugins define their options in `snake_case`), and their names should match exactly (except the case) to the upstream names. These options should be in `camelCase` (whereas most plugins define their options in `snake_case`), and their names should match exactly (except the case) to the upstream names.

View file

@ -1,13 +1,12 @@
{ {
lib, lib,
helpers,
config, config,
pkgs, pkgs,
... ...
}: let }:
helpers = import ../../helpers.nix {inherit lib;}; with helpers.vim-plugin;
in with lib; {
with helpers.vim-plugin;
with lib; {
mkCmpSourcePlugin = { mkCmpSourcePlugin = {
name, name,
extraPlugins ? [], extraPlugins ? [],
@ -63,4 +62,4 @@ in
"vsnip" = "cmp-vsnip"; "vsnip" = "cmp-vsnip";
"zsh" = "cmp-zsh"; "zsh" = "cmp-zsh";
}; };
} }

View file

@ -1,11 +1,12 @@
{ {
lib, lib,
config, config,
helpers,
pkgs, pkgs,
... ...
}: }:
with lib; let with lib; let
cmpLib = import ../cmp-helpers.nix {inherit lib config pkgs;}; cmpLib = import ../cmp-helpers.nix {inherit lib config helpers pkgs;};
cmpSourcesPluginNames = attrValues cmpLib.pluginAndSourceNames; cmpSourcesPluginNames = attrValues cmpLib.pluginAndSourceNames;
pluginModules = lists.map (name: cmpLib.mkCmpSourcePlugin {inherit name;}) cmpSourcesPluginNames; pluginModules = lists.map (name: cmpLib.mkCmpSourcePlugin {inherit name;}) cmpSourcesPluginNames;
in { in {

View file

@ -7,7 +7,7 @@
}: }:
with lib; let with lib; let
cfg = config.plugins.dap.extensions.dap-go; cfg = config.plugins.dap.extensions.dap-go;
dapHelpers = import ./dapHelpers.nix {inherit lib;}; dapHelpers = import ./dapHelpers.nix {inherit lib helpers;};
in { in {
options.plugins.dap.extensions.dap-go = { options.plugins.dap.extensions.dap-go = {
enable = mkEnableOption "dap-go"; enable = mkEnableOption "dap-go";

View file

@ -7,7 +7,7 @@
}: }:
with lib; let with lib; let
cfg = config.plugins.dap.extensions.dap-python; cfg = config.plugins.dap.extensions.dap-python;
dapHelpers = import ./dapHelpers.nix {inherit lib;}; dapHelpers = import ./dapHelpers.nix {inherit lib helpers;};
in { in {
options.plugins.dap.extensions.dap-python = { options.plugins.dap.extensions.dap-python = {
enable = mkEnableOption "dap-python"; enable = mkEnableOption "dap-python";

View file

@ -1,7 +1,8 @@
{lib, ...}: {
with lib; let lib,
helpers = import ../helpers.nix {inherit lib;}; helpers,
in rec { }:
with lib; rec {
mkAdapterType = attrs: mkAdapterType = attrs:
types.submodule { types.submodule {
options = options =

View file

@ -7,7 +7,7 @@
}: }:
with lib; let with lib; let
cfg = config.plugins.dap; cfg = config.plugins.dap;
dapHelpers = import ./dapHelpers.nix {inherit lib;}; dapHelpers = import ./dapHelpers.nix {inherit lib helpers;};
in in
with dapHelpers; { with dapHelpers; {
imports = [ imports = [

View file

@ -1,12 +1,11 @@
{ {
pkgs, pkgs,
lib, lib,
helpers,
config, config,
... ...
}: }:
with lib; let with lib; {
helpers = import ../../helpers.nix {inherit lib;};
in {
options.plugins.ts-autotag = options.plugins.ts-autotag =
helpers.neovim-plugin.extraOptionsOptions helpers.neovim-plugin.extraOptionsOptions
// { // {

View file

@ -13,13 +13,12 @@
{ {
pkgs, pkgs,
config, config,
helpers,
lib, lib,
options,
... ...
}: }:
with lib; let with lib; let
cfg = config.plugins.lsp.servers.${name}; cfg = config.plugins.lsp.servers.${name};
helpers = import ../helpers.nix {inherit lib;};
packageOption = packageOption =
if package != null if package != null

View file

@ -303,7 +303,7 @@ with lib; let
name = "ltex"; name = "ltex";
description = "ltex-ls for LanguageTool"; description = "ltex-ls for LanguageTool";
package = pkgs.ltex-ls; package = pkgs.ltex-ls;
settingsOptions = import ./ltex-settings.nix {inherit lib;}; settingsOptions = import ./ltex-settings.nix {inherit lib helpers;};
settings = cfg: {ltex = cfg;}; settings = cfg: {ltex = cfg;};
} }
{ {

View file

@ -1,7 +1,8 @@
{lib}: {
with lib; let lib,
helpers = import ../../helpers.nix {inherit lib;}; helpers,
in { }:
with lib; {
enabled = enabled =
helpers.defaultNullOpts.mkNullable helpers.defaultNullOpts.mkNullable
(with types; either bool (listOf str)) (with types; either bool (listOf str))

View file

@ -12,10 +12,10 @@
pkgs, pkgs,
config, config,
lib, lib,
helpers,
... ...
} @ args: }:
with lib; let with lib; let
helpers = import ../helpers.nix args;
cfg = config.plugins.none-ls.sources.${sourceType}.${name}; cfg = config.plugins.none-ls.sources.${sourceType}.${name};
# does this evaluate package? # does this evaluate package?
packageOption = packageOption =

View file

@ -5,7 +5,7 @@
... ...
}: }:
with lib; let with lib; let
helpers = import ./helpers.nix; cmpHelpers = import ./helpers.nix;
serverData = { serverData = {
code_actions = { code_actions = {
eslint = { eslint = {
@ -228,7 +228,7 @@ with lib; let
dataFlattened = flatten serverDataFormatted; dataFlattened = flatten serverDataFormatted;
in { in {
imports = imports =
(map helpers.mkServer dataFlattened) (map cmpHelpers.mkServer dataFlattened)
++ [ ++ [
./prettier.nix ./prettier.nix
# Introduced January 22 2024. # Introduced January 22 2024.