Skip to content

Commit ba9ce8b

Browse files
NotAShelfhorriblename
authored andcommitted
wrapper/build: add option examples; put evaluated values in literalExpression
Signed-off-by: NotAShelf <[email protected]> Change-Id: I6a6a69648220a65886994d4cac67f634a61815d5
1 parent e0827c6 commit ba9ce8b

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

modules/wrapper/build/config.nix

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
passthru.vimPlugin = false;
2323
};
2424

25-
# build a vim plugin with the given name and arguments
26-
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
27-
# instead
25+
# Build a Vim plugin with the given name and arguments.
2826
buildPlug = attrs: let
2927
pin = getPin attrs.pname;
3028
in
@@ -36,6 +34,7 @@
3634
// attrs
3735
);
3836

37+
# Build a given Treesitter grammar.
3938
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
4039

4140
pluginBuilders = {
@@ -48,6 +47,9 @@
4847
doCheck = false;
4948
};
5049

50+
# Get plugins built from source from self.packages
51+
# If adding a new plugin to be built from source, it must also be inherited
52+
# here.
5153
inherit (inputs.self.packages.${pkgs.stdenv.system}) blink-cmp avante-nvim;
5254
};
5355

@@ -71,29 +73,38 @@
7173
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
7274
# generate a wrapped Neovim package.
7375
neovim-wrapped = inputs.mnw.lib.wrap {inherit pkgs;} {
76+
appName = "nvf";
7477
neovim = config.vim.package;
78+
initLua = config.vim.builtLuaConfigRC;
79+
luaFiles = config.vim.extraLuaFiles;
80+
81+
# Plugin configurations
7582
plugins = {
7683
start = buildConfigPlugins config.vim.startPlugins;
7784
opt = buildConfigPlugins config.vim.optPlugins;
7885
};
79-
appName = "nvf";
80-
extraBinPath = config.vim.extraPackages;
81-
initLua = config.vim.builtLuaConfigRC;
82-
luaFiles = config.vim.extraLuaFiles;
86+
87+
# Providers for Neovim
8388
providers = {
89+
ruby.enable = config.vim.withRuby;
90+
nodeJs.enable = config.vim.withNodeJs;
8491
python3 = {
8592
enable = config.vim.withPython3;
8693
extraPackages = ps: map (flip builtins.getAttr ps) config.vim.python3Packages;
8794
};
88-
ruby.enable = config.vim.withRuby;
89-
nodeJs.enable = config.vim.withNodeJs;
9095
};
96+
97+
# Aliases to link `nvim` to
9198
aliases = lib.optional config.vim.viAlias "vi" ++ lib.optional config.vim.vimAlias "vim";
9299

100+
# Additional packages or Lua packages to be made available to Neovim
101+
extraBinPath = config.vim.extraPackages;
93102
extraLuaPackages = ps: map (flip builtins.getAttr ps) config.vim.luaPackages;
94103
};
95104

105+
# A store path representing the built Lua configuration.
96106
dummyInit = pkgs.writeText "nvf-init.lua" config.vim.builtLuaConfigRC;
107+
97108
# Additional helper scripts for printing and displaying nvf configuration
98109
# in your commandline.
99110
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
@@ -106,10 +117,20 @@
106117
paths = [neovim-wrapped printConfig printConfigPath];
107118
postBuild = "echo Helpers added";
108119

109-
# Allow evaluating config.vim, i.e., config.vim from the packages' passthru
110-
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
111-
# will return the configuration in full.
112-
passthru.neovimConfig = config.vim;
120+
passthru = {
121+
# Allow evaluating config.vim, i.e., config.vim from the packages' passthru
122+
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
123+
# will return the configuration in full.
124+
neovimConfig = config.vim;
125+
126+
# Also expose the helper scripts in passthru.
127+
nvfPrintConfig = printConfig;
128+
nvfPrintConfigPath = printConfigPath;
129+
130+
# In systems where we only have a package and no module, this can be used
131+
# to access the built init.lua
132+
initLua = dummyInit;
133+
};
113134

114135
meta =
115136
neovim-wrapped.meta

modules/wrapper/environment/options.nix

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
lib,
44
...
55
}: let
6-
inherit (lib.options) mkOption mkEnableOption literalMD;
6+
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
77
inherit (lib.types) package bool str listOf attrsOf;
88
inherit (lib.nvim.types) pluginsOpt extraPluginType;
99
in {
1010
options.vim = {
1111
package = mkOption {
1212
type = package;
1313
default = pkgs.neovim-unwrapped;
14+
defaultText = literalExpression "pkgs.neovim-unwrapped";
1415
description = ''
1516
The neovim package to use for the wrapper. This
1617
corresponds to the package that will be wrapped
@@ -27,21 +28,20 @@ in {
2728
viAlias = mkOption {
2829
type = bool;
2930
default = true;
31+
example = false;
3032
description = "Enable the `vi` alias for `nvim`";
3133
};
3234

3335
vimAlias = mkOption {
3436
type = bool;
3537
default = true;
38+
example = false;
3639
description = "Enable the `vim` alias for `nvim`";
3740
};
3841

3942
startPlugins = pluginsOpt {
4043
default = ["plenary-nvim"];
41-
example = ''
42-
[pkgs.vimPlugins.telescope-nvim]
43-
'';
44-
44+
example = literalExpression "[pkgs.vimPlugins.telescope-nvim]";
4545
description = ''
4646
List of plugins to load on startup. This is used
4747
internally to add plugins to Neovim's runtime.
@@ -54,9 +54,7 @@ in {
5454

5555
optPlugins = pluginsOpt {
5656
default = [];
57-
example = ''
58-
[pkgs.vimPlugins.vim-ghost]
59-
'';
57+
example = literalExpression "[pkgs.vimPlugins.vim-ghost]";
6058
description = ''
6159
List of plugins to optionally load on startup.
6260
@@ -108,7 +106,7 @@ in {
108106
'';
109107
};
110108

111-
# this defaults to `true` in the wrapper
109+
# This defaults to `true` in the wrapper
112110
# and since we pass this value to the wrapper
113111
# with an inherit, it should be `true` here as well
114112
withRuby =
@@ -120,14 +118,14 @@ in {
120118
};
121119

122120
withNodeJs = mkEnableOption ''
123-
NodeJs support in the Neovim wrapper
121+
NodeJS support in the Neovim wrapper
124122
'';
125123

126124
luaPackages = mkOption {
127125
type = listOf str;
128126
default = [];
129127
example = ''["magick" "serpent"]'';
130-
description = "List of lua packages to install";
128+
description = "List of Lua packages to install";
131129
};
132130

133131
withPython3 = mkEnableOption ''
@@ -144,7 +142,7 @@ in {
144142
pluginOverrides = mkOption {
145143
type = attrsOf package;
146144
default = {};
147-
example = ''
145+
example = literalExpression ''
148146
{
149147
lazydev-nvim = pkgs.fetchFromGitHub {
150148
owner = "folke";

0 commit comments

Comments
 (0)