-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.nix
141 lines (123 loc) · 3.61 KB
/
plugins.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
lib,
path,
stdenvNoCC,
fetchFromGitHub,
vimPlugins,
}:
let
/*
Pads a string with a leading zero if it is less than two characters long.
Type: pad :: string -> string
Example:
pad "1"
=> "01"
*/
pad = s: if builtins.stringLength s < 2 then "0" + s else s;
/*
Converts a Unix timestamp to a date string in the format "YYYY-MM-DD".
Type: dateFromUnix :: int -> string
Example:
dateFromUnix 1609459200
=> "2021-01-01"
*/
dateFromUnix =
t:
let
days = t / 86400;
z = days + 719468;
era = z / 146097;
doe = z - era * 146097;
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
y = yoe + era * 400;
doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
mp = (5 * doy + 2) / 153;
d = doy - (153 * mp + 2) / 5 + 1;
m = mp + (if mp < 10 then 3 else -9);
y' = y + (if m <= 2 then 1 else 0);
in
"${toString y'}-${pad (toString m)}-${pad (toString d)}";
/*
Formats a derivation name from a plugin name and version.
Type: formatDerivationName :: { name: string, version: string } -> string
Example:
formatDerivationName { name = "lazy.nvim", version = "0.0.1" }
=> "lazyvim-plugin-lazy-nvim-0.0.1"
*/
formatDerivationName =
{ name, version }:
let
pname = builtins.replaceStrings [ "." ] [ "-" ] name;
in
"lazyvim-plugin-${pname}-${version}";
/*
Apply list of patches to derivation, returning a new one.
Type: applyPatches :: drv -> [ string ] -> drv
*/
applyPatches =
src: patches:
stdenvNoCC.mkDerivation {
name = formatDerivationName { inherit (src.meta) name version; };
inherit src patches;
inherit (src) meta;
installPhase = ''
runHook preInstall
cp -r . $out
runHook postInstall
'';
};
/*
Make a lazy.nvim plugin spec.
See <https://lazy.folke.io/spec>
*/
makeLazySpec =
name: node: drv:
assert node.original.type == "github";
{
inherit name;
dir = "${drv}";
url = "https://github.com/${node.original.owner}/${node.original.repo}";
branch = node.original.ref;
commit = node.locked.rev;
pin = true;
};
# Build a lazy.nvim plugin package from flake.lock node.
buildPlugin =
name: node:
let
version = dateFromUnix node.locked.lastModified;
src = fetchFromGitHub {
name = formatDerivationName { inherit name version; };
inherit (node.locked) owner repo rev;
sha256 = node.locked.narHash;
};
meta = src.meta // {
inherit name version;
};
spec = makeLazySpec name node src;
in
src // { inherit meta spec; };
lockfile = builtins.fromJSON (builtins.readFile ./plugins/flake.lock);
pluginNodes = builtins.removeAttrs lockfile.nodes [ "root" ];
plugins = builtins.mapAttrs buildPlugin pluginNodes;
LazyVim-deps = builtins.fromJSON (builtins.readFile ./plugins/LazyVim.json);
mapNestedAttrs =
f: attrset:
lib.recurseIntoAttrs (
builtins.mapAttrs (_a: bs: lib.recurseIntoAttrs (builtins.mapAttrs (b: _c: (f b)) bs)) attrset
);
pluginOverrides = {
"lazy.nvim" = applyPatches plugins."lazy.nvim" [
"${path}/pkgs/applications/editors/vim/plugins/patches/lazy-nvim/no-helptags.patch"
];
"LazyVim" = plugins."LazyVim" // {
extras = mapNestedAttrs (repo: builtins.getAttr repo plugins) LazyVim-deps;
};
"blink.cmp" = vimPlugins.blink-cmp // {
spec = plugins."blink.cmp".spec // {
dir = "${vimPlugins.blink-cmp}";
};
};
};
in
lib.recurseIntoAttrs (plugins // pluginOverrides)