Skip to content

Commit 8987a01

Browse files
authored
jetbrains.plugins: fix darwin builds (#384811)
2 parents 28ab191 + 9a39cbb commit 8987a01

File tree

3 files changed

+103
-82
lines changed

3 files changed

+103
-82
lines changed

maintainers/team-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ with lib.maintainers;
568568
edwtjo
569569
leona
570570
theCapypara
571+
thiagokokada
571572
];
572573
shortName = "Jetbrains";
573574
scope = "Maintainers of the Jetbrains IDEs in nixpkgs";
Lines changed: 96 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
{ fetchurl
2-
, fetchzip
3-
, lib
4-
, stdenv
5-
, callPackage
6-
, autoPatchelfHook
7-
, glib
1+
{
2+
fetchurl,
3+
fetchzip,
4+
lib,
5+
stdenv,
6+
callPackage,
7+
autoPatchelfHook,
8+
glib,
9+
darwin,
810
}:
911

1012
let
1113
pluginsJson = builtins.fromJSON (builtins.readFile ./plugins.json);
1214
specialPluginsInfo = callPackage ./specialPlugins.nix { };
13-
fetchPluginSrc = url: hash:
15+
fetchPluginSrc =
16+
url: hash:
1417
let
1518
isJar = lib.hasSuffix ".jar" url;
1619
fetcher = if isJar then fetchurl else fetchzip;
@@ -22,21 +25,26 @@ let
2225
files = builtins.mapAttrs (key: value: fetchPluginSrc key value) pluginsJson.files;
2326
ids = builtins.attrNames pluginsJson.plugins;
2427

25-
mkPlugin = id: file:
26-
if !specialPluginsInfo ? "${id}"
27-
then files."${file}"
28+
mkPlugin =
29+
id: file:
30+
if !specialPluginsInfo ? "${id}" then
31+
files."${file}"
2832
else
29-
stdenv.mkDerivation ({
30-
name = "jetbrains-plugin-${id}";
31-
installPhase = ''
32-
runHook preInstall
33-
mkdir -p $out && cp -r . $out
34-
runHook postInstall
35-
'';
36-
src = files."${file}";
37-
} // specialPluginsInfo."${id}");
38-
39-
selectFile = id: ide: build:
33+
stdenv.mkDerivation (
34+
{
35+
name = "jetbrains-plugin-${id}";
36+
installPhase = ''
37+
runHook preInstall
38+
mkdir -p $out && cp -r . $out
39+
runHook postInstall
40+
'';
41+
src = files."${file}";
42+
}
43+
// specialPluginsInfo."${id}"
44+
);
45+
46+
selectFile =
47+
id: ide: build:
4048
if !builtins.elem ide pluginsJson.plugins."${id}".compatible then
4149
throw "Plugin with id ${id} does not support IDE ${ide}"
4250
else if !pluginsJson.plugins."${id}".builds ? "${build}" then
@@ -46,85 +54,92 @@ let
4654
else
4755
pluginsJson.plugins."${id}".builds."${build}";
4856

49-
byId = builtins.listToAttrs
50-
(map
51-
(id: {
52-
name = id;
53-
value = ide: build: mkPlugin id (selectFile id ide build);
54-
})
55-
ids);
56-
57-
byName = builtins.listToAttrs
58-
(map
59-
(id: {
60-
name = pluginsJson.plugins."${id}".name;
61-
value = byId."${id}";
62-
})
63-
ids);
64-
65-
66-
in {
57+
byId = builtins.listToAttrs (
58+
map (id: {
59+
name = id;
60+
value = ide: build: mkPlugin id (selectFile id ide build);
61+
}) ids
62+
);
63+
64+
byName = builtins.listToAttrs (
65+
map (id: {
66+
name = pluginsJson.plugins."${id}".name;
67+
value = byId."${id}";
68+
}) ids
69+
);
70+
in
71+
{
6772
# Only use if you know what youre doing
6873
raw = { inherit files byId byName; };
6974

70-
tests = callPackage ./tests.nix {};
75+
tests = callPackage ./tests.nix { };
7176

72-
addPlugins = ide: unprocessedPlugins:
77+
addPlugins =
78+
ide: unprocessedPlugins:
7379
let
74-
75-
processPlugin = plugin:
76-
if lib.isDerivation plugin then plugin else
77-
if byId ? "${plugin}" then byId."${plugin}" ide.pname ide.buildNumber else
78-
if byName ? "${plugin}" then byName."${plugin}" ide.pname ide.buildNumber else
79-
throw "Could not resolve plugin ${plugin}";
80+
processPlugin =
81+
plugin:
82+
if lib.isDerivation plugin then
83+
plugin
84+
else if byId ? "${plugin}" then
85+
byId."${plugin}" ide.pname ide.buildNumber
86+
else if byName ? "${plugin}" then
87+
byName."${plugin}" ide.pname ide.buildNumber
88+
else
89+
throw "Could not resolve plugin ${plugin}";
8090

8191
plugins = map processPlugin unprocessedPlugins;
82-
8392
in
8493
stdenv.mkDerivation rec {
8594
pname = meta.mainProgram + "-with-plugins";
8695
version = ide.version;
8796
src = ide;
8897
dontInstall = true;
89-
dontFixup = true;
98+
dontStrip = true;
9099
passthru.plugins = plugins ++ (ide.plugins or [ ]);
91100
newPlugins = plugins;
92101
disallowedReferences = [ ide ];
93-
nativeBuildInputs = (lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook) ++ (ide.nativeBuildInputs or [ ]);
102+
nativeBuildInputs =
103+
(lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook)
104+
# The buildPhase hook rewrites the binary, which invaliates the code
105+
# signature. Add the fixup hook to sign the output.
106+
++ (lib.optional stdenv.hostPlatform.isDarwin darwin.autoSignDarwinBinariesHook)
107+
++ (ide.nativeBuildInputs or [ ]);
94108
buildInputs = lib.unique ((ide.buildInputs or [ ]) ++ [ glib ]);
95109

96110
inherit (ide) meta;
97111

98112
buildPhase =
99-
let
100-
rootDir = if stdenv.hostPlatform.isDarwin then "Applications/${ide.product}.app/Contents" else meta.mainProgram;
101-
in
102-
''
103-
cp -r ${ide} $out
104-
chmod +w -R $out
105-
rm -f $out/${rootDir}/plugins/plugin-classpath.txt
106-
IFS=' ' read -ra pluginArray <<< "$newPlugins"
107-
for plugin in "''${pluginArray[@]}"
108-
do
109-
pluginfiles=$(ls $plugin);
110-
if [ $(echo $pluginfiles | wc -l) -eq 1 ] && echo $pluginfiles | grep -E "\.jar" 1> /dev/null; then
111-
# if the plugin contains a single jar file, link it directly into the plugins folder
112-
ln -s "$plugin/$(echo $pluginfiles | head -1)" $out/${rootDir}/plugins/
113-
else
114-
# otherwise link the plugin directory itself
115-
ln -s "$plugin" -t $out/${rootDir}/plugins/
116-
fi
117-
done
118-
sed "s|${ide.outPath}|$out|" \
119-
-i $(realpath $out/bin/${meta.mainProgram})
120-
121-
if test -f "$out/bin/${meta.mainProgram}-remote-dev-server"; then
122-
sed "s|${ide.outPath}|$out|" \
123-
-i $(realpath $out/bin/${meta.mainProgram}-remote-dev-server)
124-
fi
125-
126-
'' + lib.optionalString stdenv.hostPlatform.isLinux ''
127-
autoPatchelf $out
128-
'';
113+
let
114+
appDir = lib.optionalString stdenv.hostPlatform.isDarwin "Applications/${lib.escapeShellArg ide.product}.app";
115+
rootDir = if stdenv.hostPlatform.isDarwin then "${appDir}/Contents" else meta.mainProgram;
116+
in
117+
''
118+
cp -r ${ide} $out
119+
chmod +w -R $out
120+
rm -f $out/${rootDir}/plugins/plugin-classpath.txt
121+
122+
(
123+
shopt -s nullglob
124+
125+
IFS=' ' read -ra pluginArray <<< "$newPlugins"
126+
for plugin in "''${pluginArray[@]}"; do
127+
pluginfiles=($plugin)
128+
if [[ "$plugin" == *.jar ]]; then
129+
# if the plugin contains a single jar file, link it directly into the plugins folder
130+
ln -s "$plugin" $out/${rootDir}/plugins/
131+
else
132+
# otherwise link the plugin directory itself
133+
ln -s "$plugin" -t $out/${rootDir}/plugins/
134+
fi
135+
done
136+
137+
for exe in $out/bin/${meta.mainProgram}*; do
138+
if [[ -x "$exe" ]]; then
139+
substituteInPlace $(realpath "$exe") --replace-warn '${ide.outPath}' $out
140+
fi
141+
done
142+
)
143+
'';
129144
};
130145
}

pkgs/applications/editors/jetbrains/plugins/tests.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@
2727
in
2828
writeText "jb-ides" paths;
2929

30-
clion-with-vim = jetbrains.plugins.addPlugins jetbrains.clion [ "ideavim" ];
30+
idea-ce-with-plugins = jetbrains.plugins.addPlugins jetbrains.idea-community [
31+
"ideavim"
32+
"nixidea"
33+
# test JAR plugins
34+
"wakatime"
35+
];
3136
}

0 commit comments

Comments
 (0)