Skip to content

Commit 7c4fe30

Browse files
committed
lib/options: introduce new mkPackageOption for dependencies
1 parent 2636769 commit 7c4fe30

File tree

15 files changed

+51
-85
lines changed

15 files changed

+51
-85
lines changed

lib/options.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ rec {
155155
mkNullable nixvimTypes.highlight default (if desc == "" then "Highlight settings." else desc);
156156
};
157157

158+
mkPackageOption =
159+
{
160+
name ? null, # Can be null if a custom description is given.
161+
default,
162+
description ? null,
163+
example ? null,
164+
}:
165+
mkOption {
166+
type = with types; nullOr package;
167+
inherit default example;
168+
description =
169+
if description == null then
170+
''
171+
Which package to use for `${name}`.
172+
Set to `null` to disable its automatic installation.
173+
''
174+
else
175+
description;
176+
};
177+
158178
mkPluginPackageOption =
159179
name: default:
160180
mkOption {

plugins/completion/cmp/sources/cmp-fish.nix

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
lib,
33
config,
44
pkgs,
5+
helpers,
56
...
67
}:
78
with lib;
@@ -12,14 +13,9 @@ in
1213
meta.maintainers = [ maintainers.GaetanLepage ];
1314

1415
options.plugins.cmp-fish = {
15-
fishPackage = mkOption {
16-
type = with types; nullOr package;
16+
fishPackage = helpers.mkPackageOption {
17+
name = "fish";
1718
default = pkgs.fish;
18-
example = "null";
19-
description = ''
20-
Which package to use for `fish`.
21-
Set to `null` to disable its automatic installation.
22-
'';
2319
};
2420
};
2521

plugins/git/gitsigns/default.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,9 @@ helpers.neovim-plugin.mkNeovimPlugin config {
281281
];
282282

283283
extraOptions = {
284-
gitPackage = mkOption {
285-
type = with types; nullOr package;
284+
gitPackage = helpers.mkPackageOption {
285+
name = "git";
286286
default = pkgs.git;
287-
description = ''
288-
Which package to use for `git`.
289-
Set to `null` to prevent the installation.
290-
'';
291287
};
292288
};
293289

plugins/git/lazygit.nix

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,14 @@ helpers.vim-plugin.mkVimPlugin config {
6464
};
6565

6666
extraOptions = {
67-
gitPackage = mkOption {
68-
type = with types; nullOr package;
67+
gitPackage = helpers.mkPackageOption {
68+
name = "git";
6969
default = pkgs.git;
70-
example = null;
71-
description = ''
72-
The `git` package to use.
73-
Set to `null` to not install any package.
74-
'';
7570
};
7671

77-
lazygitPackage = mkOption {
78-
type = with types; nullOr package;
72+
lazygitPackage = helpers.mkPackageOption {
73+
name = "lazygit";
7974
default = pkgs.lazygit;
80-
example = null;
81-
description = ''
82-
The `lazygit` package to use.
83-
Set to `null` to not install any package.
84-
'';
8575
};
8676
};
8777

plugins/languages/godot.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ helpers.vim-plugin.mkVimPlugin config {
1515
maintainers = [ maintainers.GaetanLepage ];
1616

1717
extraOptions = {
18-
godotPackage = mkOption {
19-
type = with types; nullOr package;
18+
godotPackage = helpers.mkPackageOption {
19+
name = "godot";
2020
default = pkgs.godot_4;
21-
description = ''
22-
Which package to use for `godot`.
23-
Set to `null` to prevent the installation.
24-
'';
2521
};
2622
};
2723

plugins/languages/lean.nix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ in
1515

1616
package = helpers.mkPluginPackageOption "lean-nvim" pkgs.vimPlugins.lean-nvim;
1717

18-
leanPackage = mkOption {
19-
type = with types; nullOr package;
18+
leanPackage = helpers.mkPackageOption {
19+
name = "lean";
2020
default = pkgs.lean4;
21-
description = "Which package to use for lean.";
22-
example = null;
2321
};
2422

2523
lsp = helpers.defaultNullOpts.mkNullable (

plugins/languages/ledger.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ mkVimPlugin config {
4646
];
4747

4848
extraOptions = {
49-
ledgerPackage = mkOption {
50-
type = with types; nullOr package;
49+
ledgerPackage = helpers.mkPackageOption {
50+
name = "ledger";
5151
default = pkgs.ledger;
52-
description = ''
53-
The package to install for `ledger`.
54-
Set to `null` for disabling installation.
55-
'';
5652
};
5753
};
5854

plugins/languages/rust-tools.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ in
1313
options.plugins.rust-tools = helpers.neovim-plugin.extraOptionsOptions // {
1414
enable = mkEnableOption "rust tools plugins";
1515
package = helpers.mkPluginPackageOption "rust-tools" pkgs.vimPlugins.rust-tools-nvim;
16-
serverPackage = mkOption {
17-
type = with types; nullOr package;
16+
serverPackage = helpers.mkPackageOption {
17+
name = "rust-analyzer";
1818
default = pkgs.rust-analyzer;
19-
description = "Package to use for rust-analyzer. rust-analyzer will not be installed if this is set to `null`";
2019
};
2120

2221
executor = helpers.defaultNullOpts.mkEnumFirstDefault [

plugins/languages/rustaceanvim.nix

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ in
1717

1818
package = helpers.mkPluginPackageOption "rustaceanvim" pkgs.vimPlugins.rustaceanvim;
1919

20-
rustAnalyzerPackage = mkOption {
21-
type = with types; nullOr package;
20+
rustAnalyzerPackage = helpers.mkPackageOption {
21+
name = "rust-analyzer";
2222
default = pkgs.rust-analyzer;
23-
description = ''
24-
Which package to use for `rust-analyzer`.
25-
Set to `null` to disable its automatic installation.
26-
'';
27-
example = null;
2823
};
2924

3025
tools =
@@ -41,7 +36,7 @@ in
4136
{
4237
executor = helpers.defaultNullOpts.mkEnum executors "termopen" ''
4338
`{execute_command} (fun(cmd:string,args:string[],cwd:string|nil,opts?:RustaceanExecutorOpts))`
44-
The executor to use for runnables/debuggables.
39+
The executor to use for runnables/debuggables.
4540
4641
Example:
4742
```lua
@@ -62,7 +57,7 @@ in
6257

6358
testExecutor = helpers.defaultNullOpts.mkEnum testExecutors "termopen" ''
6459
`{execute_command} (fun(cmd:string,args:string[],cwd:string|nil,opts?:RustaceanExecutorOpts))`
65-
The executor to use for runnables that are tests/testables
60+
The executor to use for runnables that are tests/testables
6661
'';
6762

6863
crateTestExecutor = helpers.defaultNullOpts.mkEnum testExecutors "termopen" ''

plugins/languages/texpresso.nix

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ helpers.vim-plugin.mkVimPlugin config {
1616
maintainers = [ maintainers.nickhu ];
1717

1818
extraOptions = {
19-
texpressoPackage = mkOption {
20-
type = with types; nullOr package;
19+
texpressoPackage = helpers.mkPackageOption {
20+
name = "texpresso";
2121
default = pkgs.texpresso;
22-
example = null;
23-
description = ''
24-
The `texpresso` package to use.
25-
Set to `null` to not install any package.
26-
'';
2722
};
2823
};
2924

plugins/languages/treesitter/treesitter.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ in
3737
description = "Either \"all\" or a list of languages";
3838
};
3939

40-
gccPackage = mkOption {
41-
type = with types; nullOr package;
40+
gccPackage = helpers.mkPackageOption {
4241
default = if cfg.nixGrammars then null else pkgs.gcc;
43-
example = null;
4442
description = ''
4543
Which package (if any) to be added as the GCC compiler.
4644
This is required to build grammars if you are not using `nixGrammars`.

plugins/languages/vimtex.nix

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@ helpers.vim-plugin.mkVimPlugin config {
5656
};
5757

5858
extraOptions = {
59-
texlivePackage = mkOption {
60-
type = with types; nullOr package;
59+
texlivePackage = helpers.mkPackageOption {
60+
name = "texlive";
6161
default = pkgs.texlive.combined.scheme-medium;
62-
example = null;
63-
description = ''
64-
The package to install for `textlive.
65-
Set to `null` for not installing `texlive` at all.
66-
'';
6762
};
6863
};
6964

plugins/utils/fzf-lua.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ helpers.neovim-plugin.mkNeovimPlugin config {
4141
inherit settingsOptions settingsExample;
4242

4343
extraOptions = {
44-
fzfPackage = mkOption {
45-
type = with types; nullOr package;
44+
fzfPackage = helpers.mkPackageOption {
45+
name = "fzf";
4646
default = pkgs.fzf;
47-
description = ''
48-
The fzf package to use.
49-
Set to `null` to not install any package.
50-
'';
5147
example = pkgs.skim;
5248
};
5349

plugins/utils/spectre.nix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ helpers.neovim-plugin.mkNeovimPlugin config {
246246
replaceDefaultPackage = replacePackages.${toString userCommandSettings.replace.cmd} or null;
247247
in
248248
{
249-
findPackage = mkOption {
250-
type = with types; nullOr package;
249+
findPackage = helpers.mkPackageOption {
251250
default = findDefaultPackage;
252251
description = ''
253252
Which package to install for the find command.
@@ -257,8 +256,7 @@ helpers.neovim-plugin.mkNeovimPlugin config {
257256
'';
258257
};
259258

260-
replacePackage = mkOption {
261-
type = with types; nullOr package;
259+
replacePackage = helpers.mkPackageOption {
262260
default = replaceDefaultPackage;
263261
description = ''
264262
Which package to install for the find command.

plugins/utils/todo-comments.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ in
3030

3131
package = helpers.mkPluginPackageOption "todo-comments" pkgs.vimPlugins.todo-comments-nvim;
3232

33-
ripgrepPackage = mkOption {
34-
type = with types; nullOr package;
33+
ripgrepPackage = helpers.mkPackageOption {
3534
default = pkgs.ripgrep;
36-
example = null;
3735
description = "Which package (if any) to be added for file search support in todo-comments.";
3836
};
3937

0 commit comments

Comments
 (0)