Skip to content

Commit

Permalink
jetbrains: add plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
GenericNerdyUsername committed Nov 19, 2022
1 parent 2e4fe94 commit adcfa5f
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 24 deletions.
3 changes: 2 additions & 1 deletion pkgs/applications/editors/jetbrains/darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
, productShort ? product
, src
, version
, plugins ? []
, ...
}:

let
loname = lib.toLower productShort;
in
stdenvNoCC.mkDerivation {
inherit pname meta src version;
inherit pname meta src version plugins;
desktopName = product;
installPhase = ''
runHook preInstall
Expand Down
2 changes: 2 additions & 0 deletions pkgs/applications/editors/jetbrains/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,6 @@ in
update-channel = products.webstorm.update-channel;
};

plugins = callPackage ./plugins {};

}
58 changes: 35 additions & 23 deletions pkgs/applications/editors/jetbrains/linux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
, vmopts ? null
}:

{ pname, product, productShort ? product, version, src, wmClass, jdk, meta, extraLdPath ? [], extraWrapperArgs ? [] }@args:
{ pname
, product
, productShort ? product
, version
, src
, wmClass
, jdk
, meta
, extraLdPath ? []
, extraWrapperArgs ? []
}@args:

with lib;

Expand Down Expand Up @@ -34,28 +44,30 @@ with stdenv; lib.makeOverridable mkDerivation (rec {
nativeBuildInputs = [ makeWrapper patchelf unzip ];

postPatch = ''
get_file_size() {
local fname="$1"
echo $(ls -l $fname | cut -d ' ' -f5)
}
munge_size_hack() {
local fname="$1"
local size="$2"
strip $fname
truncate --size=$size $fname
}
interpreter=$(echo ${stdenv.cc.libc}/lib/ld-linux*.so.2)
if [[ "${stdenv.hostPlatform.system}" == "x86_64-linux" && -e bin/fsnotifier64 ]]; then
target_size=$(get_file_size bin/fsnotifier64)
patchelf --set-interpreter "$interpreter" bin/fsnotifier64
munge_size_hack bin/fsnotifier64 $target_size
else
target_size=$(get_file_size bin/fsnotifier)
patchelf --set-interpreter "$interpreter" bin/fsnotifier
munge_size_hack bin/fsnotifier $target_size
fi
get_file_size() {
local fname="$1"
echo $(ls -l $fname | cut -d ' ' -f5)
}
munge_size_hack() {
local fname="$1"
local size="$2"
strip $fname
truncate --size=$size $fname
}
interpreter=$(echo ${stdenv.cc.libc}/lib/ld-linux*.so.2)
if [[ "${stdenv.hostPlatform.system}" == "x86_64-linux" && -e bin/fsnotifier64 ]]; then
target_size=$(get_file_size bin/fsnotifier64)
patchelf --set-interpreter "$interpreter" bin/fsnotifier64
munge_size_hack bin/fsnotifier64 $target_size
else
target_size=$(get_file_size bin/fsnotifier)
patchelf --set-interpreter "$interpreter" bin/fsnotifier
munge_size_hack bin/fsnotifier $target_size
fi
rm -rf jbr
'';

installPhase = ''
Expand Down
72 changes: 72 additions & 0 deletions pkgs/applications/editors/jetbrains/plugins/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{ fetchurl
, fetchzip
, lib
, stdenv
, callPackage
, autoPatchelfHook
}: with builtins;
# These functions do NOT check for plugin compatibility
# Check by installing manually first

let
fetchPluginSrc = { hash, url, id, name, special ? false, version ? null, ... }: let
isJar = lib.hasSuffix ".jar" url;
fetcher = if isJar then fetchurl else fetchzip;
in fetcher {
executable = isJar;
inherit url hash;
passthru = { inherit id name special version; };
};

mkPlugin = x: stdenv.mkDerivation ({installPhase = "mkdir $out && cp -r . $out";} // x);

specialPluginsInfo = callPackage ./specialPlugins.nix {};
plugins = fromJSON (readFile ./plugins.json);
pluginsWithSpecial = mapAttrs
(id: value: value // { special = specialPluginsInfo ? "${id}"; inherit id; } // (specialPluginsInfo."${id}" or {})) plugins;
pluginsWithSrcs = mapAttrs
(id: value: value // { src = fetchPluginSrc value; }) pluginsWithSpecial;
pluginsWithResult = mapAttrs
(id: value: { result = if value.special then mkPlugin value else value.src; } // value) pluginsWithSrcs;
byId = mapAttrs (id: value: value.result) pluginsWithResult;
byName = lib.mapAttrs'
(key: value: lib.attrsets.nameValuePair value.name value.result) pluginsWithResult;

in rec {
inherit fetchPluginSrc byId byName;

addPlugins = ide: plugins: stdenv.mkDerivation rec {
pname = meta.mainProgram + "-with-plugins";
version = ide.version;
src = ide;
dontInstall = true;
dontFixup = true;
passthru.plugins = plugins ++ (ide.plugins or []);
newPlugins = plugins;
disallowedReferences = [ ide ];
nativeBuildInputs = [ autoPatchelfHook ] ++ (ide.nativeBuildInputs or []);
buildInputs = ide.buildInputs or [];

inherit (ide) meta;

buildPhase = let
pluginCmdsLines = map (plugin: "ln -s ${plugin} \"$out\"/${meta.mainProgram}/plugins/${baseNameOf plugin}") plugins;
pluginCmds = concatStringsSep "\n" pluginCmdsLines;
extraBuildPhase = rec {
clion = ''
sed "s|${ide}|$out|" -i $out/bin/.clion-wrapped
autoPatchelf $out/clion/bin
'';
};
in ''
cp -r ${ide} $out
chmod +w -R $out
IFS=' ' read -ra pluginArray <<< "$newPlugins"
for plugin in "''${pluginArray[@]}"
do
ln -s "$plugin" -t $out/${meta.mainProgram}/plugins/
done
sed "s|${ide.outPath}|$out|" -i $out/bin/${meta.mainProgram}
'' + (extraBuildPhase."${ide.meta.mainProgram}" or "");
};
}
98 changes: 98 additions & 0 deletions pkgs/applications/editors/jetbrains/plugins/plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"164": {
"url": "https://plugins.jetbrains.com/files/164/245831/IdeaVim-2.0.0.zip",
"hash": "sha256-ufRfFGDLEHSdmXGgeO6EkuERDO1etWtjXS5kYeNthYE=",
"name": "ideavim",
"version": 245831
},
"631": {
"url": "https://plugins.jetbrains.com/files/631/252982/python-223.7571.58.zip",
"hash": "sha256-ZzWa3Yzma0JN8dmaLWl2ixiNyDqd4Yr7WilgMPCRq/4=",
"name": "python",
"version": 252982
},
"4230": {
"url": "https://plugins.jetbrains.com/files/4230/92719/BashSupport-1.8.0.202.zip",
"hash": "sha256-c6MOV9RmDPZcg+2reacK3O2BQuMnqxYjvLh5leQ7lkI=",
"name": "bashsupport",
"version": 92719
},
"6954": {
"url": "https://plugins.jetbrains.com/files/6954/248763/kotlin-plugin-222-1.7.21-release-272-IJ4167.29.zip",
"hash": "sha256-SDDAm4HjhJIEOmb+guKPzvhaUVC3oljd8GviABp0Pv8=",
"name": "kotlin",
"version": 248763
},
"6981": {
"url": "https://plugins.jetbrains.com/files/6981/253972/ini-223.7571.73.zip",
"hash": "sha256-K3WaF6XWk7cZ243y9pQKKl2EYHzV/cljdADCzPT2+lM=",
"name": "ini",
"version": 253972
},
"7322": {
"url": "https://plugins.jetbrains.com/files/7322/253079/python-ce-223.7571.58.zip",
"hash": "sha256-CWLWG4jTOY0MrvGljn54wVu4FT0v4B7TjG5S/m09I0k=",
"name": "python-community-edition",
"version": 253079
},
"8182": {
"url": "https://plugins.jetbrains.com/files/8182/248217/intellij-rust-0.4.182.4996-222.zip",
"hash": "sha256-fUrQICVIlhCvQ8Q7Rm05bA9zYF7vSn+rRpuNqI58A6A=",
"name": "rust",
"version": 248217
},
"8182-beta": {
"url": "https://plugins.jetbrains.com/files/8182/251335/intellij-rust-0.4.183.5013-222-beta.zip",
"hash": "sha256-DzvZ+MQiRsv+rrya66DCuWWfirDemtZbl4bmU+GnDuA=",
"name": "rust-beta",
"version": 251335
},
"8554": {
"url": "https://plugins.jetbrains.com/files/8554/253994/featuresTrainer-223.7571.73.zip",
"hash": "sha256-3Pax/BbPR+Uir/08RMUydZv4ZDvK9L7yCLM/wUKlcUA=",
"name": "ide-features-trainer",
"version": 253994
},
"8607": {
"url": "https://plugins.jetbrains.com/files/8607/235206/NixIDEA-0.4.0.6.zip",
"hash": "sha256-DZVCygkVVS2r0ZJXqLyuAUOZSs90OLla/DEOpn8xRRw=",
"name": "nixidea",
"version": 235206
},
"9568": {
"url": "https://plugins.jetbrains.com/files/9568/253077/go-plugin-223.7571.58.zip",
"hash": "sha256-VQidLLtv+kS2S95CsQIxAQbiHjCT0gBD8i9X7mJr7mY=",
"name": "go",
"version": 253077
},
"10037": {
"url": "https://plugins.jetbrains.com/files/10037/250022/CSVEditor-3.0.1-223.zip",
"hash": "sha256-M6vDRwux3TqnHXs1/Te1Nh3ratphwhvBZSa/9ePajTM=",
"name": "csv",
"version": 250022
},
"12559": {
"url": "https://plugins.jetbrains.com/files/12559/254000/keymap-eclipse-223.7571.73.zip",
"hash": "sha256-2nPv8aGfboA/9gWsoMz5oGJ4vV8DvmBvu1IrfrRuLMg=",
"name": "eclipse-keymap",
"version": 254000
},
"13017": {
"url": "https://plugins.jetbrains.com/files/13017/254018/keymap-visualStudio-223.7571.73.zip",
"hash": "sha256-86PwIBwJhhDjgJJRL0wIqu6HXIkVv/aArigZRhVP7EI=",
"name": "visual-studio-keymap",
"version": 254018
},
"14059": {
"url": "https://plugins.jetbrains.com/files/14059/82616/darcula-pitch-black.jar",
"hash": "sha256-eXInfAqY3yEZRXCAuv3KGldM1pNKEioNwPB0rIGgJFw=",
"name": "darcula-pitch-black",
"version": 82616
},
"18444": {
"url": "https://plugins.jetbrains.com/files/18444/165585/NetBeans6.5Keymap.zip",
"hash": "sha256-KrzZTKZMQqoEMw+vDUv2jjs0EX0leaPBkU8H/ecq/oI=",
"name": "netbeans-6-5-keymap",
"version": 165585
}
}
23 changes: 23 additions & 0 deletions pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ delve, autoPatchelfHook, stdenv }:
# This is a list of plugins that need special treatment. For example, the go plugin (id is 9568) comes with delve, a
# debugger, but that needs various linking fixes. The changes here replace it with the system one.
{
"631" = { # Python
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [ stdenv.cc.cc.lib ];
};
"7322" = { # Python community edition
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [ stdenv.cc.cc.lib ];
};
"8182" = { # Rust
nativeBuildInputs = [ autoPatchelfHook ];
commands = "chmod +x -R bin";
};
"9568" = { # Go
buildInputs = [ delve ];
commands = let
arch = (if stdenv.isLinux then "linux" else "mac") + (if stdenv.isAarch64 then "arm" else "");
in "ln -sf ${delve}/bin/dlv lib/dlv/${arch}/dlv";
};
}
Loading

0 comments on commit adcfa5f

Please sign in to comment.