Skip to content

Commit ada161d

Browse files
committed
plugins/pckr: init
1 parent 77c5fe8 commit ada161d

File tree

2 files changed

+240
-0
lines changed

2 files changed

+240
-0
lines changed

plugins/by-name/pckr/default.nix

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
lib,
3+
pkgs,
4+
...
5+
}:
6+
let
7+
inherit (lib) mkOption types;
8+
in
9+
lib.nixvim.plugins.mkNeovimPlugin {
10+
name = "pckr";
11+
packPathName = "pckr.nvim";
12+
package = "pckr-nvim";
13+
14+
maintainers = [ lib.maintainers.GaetanLepage ];
15+
16+
extraOptions = {
17+
gitPackage = lib.mkPackageOption pkgs "git" {
18+
nullable = true;
19+
};
20+
21+
plugins = lib.mkOption {
22+
default = [ ];
23+
type =
24+
let
25+
pluginType = lib.types.either types.str (
26+
types.submodule {
27+
freeformType = with types; attrsOf anything;
28+
options = {
29+
path = mkOption {
30+
type = types.str;
31+
example = "nvim-treesitter/nvim-treesitter";
32+
description = ''
33+
Repo/path to the plugin.
34+
'';
35+
};
36+
requires = mkOption {
37+
type = types.listOf pluginType;
38+
default = [ ];
39+
example = [
40+
"kyazdani42/nvim-web-devicons"
41+
];
42+
description = ''
43+
Dependencies for this plugin.
44+
'';
45+
};
46+
};
47+
}
48+
);
49+
in
50+
types.listOf pluginType;
51+
example = [
52+
"9mm/vim-closer"
53+
"~/projects/personal/hover.nvim"
54+
{
55+
path = "tpope/vim-dispatch";
56+
cond = [
57+
{ __raw = "require('pckr.loader.cmd')('Dispatch')"; }
58+
];
59+
}
60+
{
61+
path = "nvim-treesitter/nvim-treesitter";
62+
run = ":TSUpdate";
63+
}
64+
];
65+
description = ''
66+
List of plugins to install with pckr.
67+
'';
68+
};
69+
};
70+
71+
settingsExample = {
72+
autoremove = true;
73+
pack_dir.__raw = "vim.env.VIM .. '/pckr'";
74+
lockfile.path.__raw = "vim.fn.stdpath('config') .. '/pckr/lockfile.lua'";
75+
};
76+
77+
extraConfig = cfg: {
78+
extraPackages = [ cfg.gitPackage ];
79+
80+
plugins.pckr.luaConfig = {
81+
# Otherwise pckr can't find itself
82+
pre = ''
83+
vim.opt.rtp:prepend("${cfg.package}")
84+
'';
85+
86+
# Add plugins after calling require('pckr').setup()
87+
post =
88+
let
89+
normalizePlugin =
90+
p:
91+
if builtins.isString p then
92+
p
93+
else
94+
builtins.removeAttrs p [
95+
"path"
96+
"requires"
97+
]
98+
// {
99+
__unkeyed = p.path;
100+
requires = normalizePlugins p.requires;
101+
};
102+
103+
normalizePlugins = lib.map normalizePlugin;
104+
105+
plugins = normalizePlugins cfg.plugins;
106+
107+
packedPlugins = if lib.length plugins == 1 then builtins.head plugins else plugins;
108+
in
109+
lib.mkIf (cfg.plugins != [ ]) ''
110+
require('pckr').add(${lib.nixvim.toLuaObject packedPlugins})
111+
'';
112+
};
113+
};
114+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
empty = {
3+
plugins.pckr.enable = true;
4+
};
5+
6+
defaults = {
7+
plugins.pckr = {
8+
enable = true;
9+
10+
settings = {
11+
pack_dir.__raw = "require('pckr.util').join_paths(vim.fn.stdpath('data'), 'site')";
12+
max_jobs = null;
13+
autoremove = false;
14+
autoinstall = true;
15+
git = {
16+
cmd = "git";
17+
clone_timeout = 60;
18+
default_url_format = "https://github.com/%s";
19+
};
20+
log = {
21+
level = "warn";
22+
};
23+
lockfile = {
24+
path.__raw = "require('pckr.util').join_paths(vim.fn.stdpath('config'), 'pckr', 'lockfile.lua')";
25+
};
26+
};
27+
};
28+
};
29+
30+
example = {
31+
plugins.pckr = {
32+
enable = true;
33+
34+
# https://github.com/lewis6991/pckr.nvim?tab=readme-ov-file#example
35+
plugins = [
36+
# Simple plugins can be specified as strings
37+
"9mm/vim-closer"
38+
39+
# Lazy loading:
40+
# Load on a specific command
41+
{
42+
path = "tpope/vim-dispatch";
43+
cond = [
44+
{ __raw = "require('pckr.loader.cmd')('Dispatch')"; }
45+
];
46+
}
47+
48+
# Load on specific keymap
49+
{
50+
path = "tpope/vim-commentary";
51+
cond.__raw = "require('pckr.loader.keys')('n', 'gc')";
52+
}
53+
54+
# Load on specific commands
55+
# Also run code after load (see the "config" key)
56+
{
57+
path = "w0rp/ale";
58+
cond.__raw = "require('pckr.loader.cmd')('ALEEnable')";
59+
config.__raw = ''
60+
function()
61+
vim.cmd[[ALEEnable]]
62+
end
63+
'';
64+
}
65+
66+
# Local plugins can be included
67+
"~/projects/personal/hover.nvim"
68+
69+
# Plugins can have post-install/update hooks
70+
{
71+
path = "iamcco/markdown-preview.nvim";
72+
run = "cd app && yarn install";
73+
cond.__raw = "require('pckr.loader.cmd')('MarkdownPreview')";
74+
}
75+
76+
# Post-install/update hook with neovim command
77+
{
78+
path = "nvim-treesitter/nvim-treesitter";
79+
run = ":TSUpdate";
80+
}
81+
82+
# Post-install/update hook with call of vimscript function with argument
83+
{
84+
path = "glacambre/firenvim";
85+
run.__raw = ''
86+
function()
87+
vim.fn['firenvim#install'](0)
88+
end
89+
'';
90+
}
91+
92+
# Use specific branch, dependency and run lua file after load
93+
{
94+
path = "glepnir/galaxyline.nvim";
95+
branch = "main";
96+
requires = [
97+
"kyazdani42/nvim-web-devicons"
98+
];
99+
config.__raw = ''
100+
function()
101+
require'statusline'
102+
end
103+
'';
104+
}
105+
106+
# Run config *before* the plugin is loaded
107+
{
108+
path = "whatyouhide/vim-lengthmatters";
109+
config_pre.__raw = ''
110+
function()
111+
vim.g.lengthmatters_highlight_one_column = 1
112+
vim.g.lengthmatters_excluded = {'pckr'}
113+
end
114+
'';
115+
}
116+
];
117+
};
118+
};
119+
120+
no-packages = {
121+
plugins.pckr = {
122+
enable = true;
123+
gitPackage = null;
124+
};
125+
};
126+
}

0 commit comments

Comments
 (0)