forked from theCapypara/nix-jetbrains-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.nix
96 lines (90 loc) · 2.12 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
{
lib,
fetchurl,
fetchzip,
stdenv,
}:
with builtins;
with lib;
let
SEPARATOR = "/--/";
fetchPluginSrc =
{ url, hash }:
let
isJar = hasSuffix ".jar" url;
fetcher = if isJar then fetchurl else fetchzip;
in
fetcher {
executable = isJar;
inherit url hash;
};
downloadPlugin =
{
name,
version,
url,
hash,
}:
let
isJar = hasSuffix ".jar" url;
installPhase =
if isJar then
''
runHook preInstall
mkdir -p $out && cp $src $out
runHook postInstall
''
else
''
runHook preInstall
mkdir -p $out && cp -r . $out
runHook postInstall
'';
in
stdenv.mkDerivation {
inherit name version;
src = fetchPluginSrc { inherit url hash; };
dontUnpack = isJar;
inherit installPhase;
};
readGeneratedDir = attrNames (
filterAttrs (name: _: hasSuffix ".json" name) (readDir ./generated/ides)
);
# Folds into the set of { IDENAME = { VERSION = [ x y ]; }; }
buildIdeVersionMap = (
accu: value:
accu
// {
"${value.version}" = (accu."${value.version}" or { }) // value.value;
}
);
# Find and construct plugin from a list of plugins
findPlugin =
pluginList: name: version:
let
key = "${name}${SEPARATOR}${version}";
match = pluginList."${key}";
in
{
inherit name version;
url = "http://kafpi.local/${match.p}";
hash = "sha256-${match.h}";
};
allPlugins = fromJSON (readFile ./generated/all_plugins.json);
in
(groupBy' buildIdeVersionMap { } (x: x.ideName) (
map (
jsonFile:
let
# Split the JSON filename into IDENAME-VERSION and remove json suffix
parts = splitString "-" (removeSuffix ".json" jsonFile);
in
{
ideName = concatStrings (intersperse "-" (init parts));
version = elemAt parts ((length parts) - 1);
value = mapAttrs (k: v: downloadPlugin (findPlugin allPlugins k v)) (
fromJSON (readFile (./generated/ides + "/${jsonFile}"))
);
}
) readGeneratedDir
))