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 Mar 25, 2023
1 parent 0fc009e commit 7f673bc
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 14 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
4 changes: 3 additions & 1 deletion pkgs/applications/editors/jetbrains/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ let
providing you almost everything you need for your comfortable
and productive development!
'';
maintainers = with maintainers; [ ];
maintainers = with maintainers; [ genericnerdyusername ];
};
}).overrideAttrs (finalAttrs: previousAttrs: lib.optionalAttrs cythonSpeedup {
buildInputs = with python3.pkgs; [ python3 setuptools ];
Expand Down Expand Up @@ -467,4 +467,6 @@ in
update-channel = products.webstorm.update-channel;
};

plugins = callPackage ./plugins {};

}
34 changes: 22 additions & 12 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:

let loName = lib.toLower productShort;
hiName = lib.toUpper productShort;
Expand Down Expand Up @@ -32,17 +42,17 @@ 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
}
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
}
rm -rf jbr
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": "2.0.0"
},
"631": {
"url": "https://plugins.jetbrains.com/files/631/252982/python-223.7571.58.zip",
"hash": "sha256-ZzWa3Yzma0JN8dmaLWl2ixiNyDqd4Yr7WilgMPCRq/4=",
"name": "python",
"version": "223.7571.58"
},
"4230": {
"url": "https://plugins.jetbrains.com/files/4230/92719/BashSupport-1.8.0.202.zip",
"hash": "sha256-c6MOV9RmDPZcg+2reacK3O2BQuMnqxYjvLh5leQ7lkI=",
"name": "bashsupport",
"version": "1.8.0.202"
},
"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": "222-1.7.21-release-272-IJ4167.29"
},
"6981": {
"url": "https://plugins.jetbrains.com/files/6981/255105/ini-223.7571.98.zip",
"hash": "sha256-alzFuJ0cEVL311Y4nXW+JGM6PlKoXu3y5G/Hl17npBQ=",
"name": "ini",
"version": "223.7571.98"
},
"7322": {
"url": "https://plugins.jetbrains.com/files/7322/253079/python-ce-223.7571.58.zip",
"hash": "sha256-CWLWG4jTOY0MrvGljn54wVu4FT0v4B7TjG5S/m09I0k=",
"name": "python-community-edition",
"version": "223.7571.58"
},
"8182": {
"url": "https://plugins.jetbrains.com/files/8182/261493/intellij-rust-0.4.184.5057-223.zip",
"hash": "sha256-wRn5UrtvQYKgG5TX+Tq9LKjQHqv8lSWfiQVKSm9FtA0=",
"name": "rust",
"version": "0.4.184.5057-223"
},
"8182-beta": {
"url": "https://plugins.jetbrains.com/files/8182/261812/intellij-rust-0.4.184.5059-223-beta.zip",
"hash": "sha256-FjIn2EXf4uyGTsN/Hb8ME5EZhhEI/Q1cbTkqLUnJSgg=",
"name": "rust-beta",
"version": "0.4.184.5059-223-beta"
},
"8554": {
"url": "https://plugins.jetbrains.com/files/8554/255591/featuresTrainer-223.7571.93.zip",
"hash": "sha256-jA+pk7caXpaJVSDGOwlSnsOCp6Kz6szn9kTuLukb+tE=",
"name": "ide-features-trainer",
"version": "223.7571.93"
},
"8607": {
"url": "https://plugins.jetbrains.com/files/8607/235206/NixIDEA-0.4.0.6.zip",
"hash": "sha256-DZVCygkVVS2r0ZJXqLyuAUOZSs90OLla/DEOpn8xRRw=",
"name": "nixidea",
"version": "0.4.0.6"
},
"9568": {
"url": "https://plugins.jetbrains.com/files/9568/253077/go-plugin-223.7571.58.zip",
"hash": "sha256-VQidLLtv+kS2S95CsQIxAQbiHjCT0gBD8i9X7mJr7mY=",
"name": "go",
"version": "223.7571.58"
},
"10037": {
"url": "https://plugins.jetbrains.com/files/10037/250022/CSVEditor-3.0.1-223.zip",
"hash": "sha256-M6vDRwux3TqnHXs1/Te1Nh3ratphwhvBZSa/9ePajTM=",
"name": "csv",
"version": "3.0.1-223"
},
"12559": {
"url": "https://plugins.jetbrains.com/files/12559/255100/keymap-eclipse-223.7571.98.zip",
"hash": "sha256-BRzZF8WIGX427QdvRkbQKZv26h6kwNZoHQSNPR+v03Q=",
"name": "eclipse-keymap",
"version": "223.7571.98"
},
"13017": {
"url": "https://plugins.jetbrains.com/files/13017/255112/keymap-visualStudio-223.7571.98.zip",
"hash": "sha256-TEcZaDcFJD9B2ur9GhxBoyC/YQjbYFW2ZCFCI9yeuls=",
"name": "visual-studio-keymap",
"version": "223.7571.98"
},
"14059": {
"url": "https://plugins.jetbrains.com/files/14059/82616/darcula-pitch-black.jar",
"hash": "sha256-eXInfAqY3yEZRXCAuv3KGldM1pNKEioNwPB0rIGgJFw=",
"name": "darcula-pitch-black",
"version": "1.0.0"
},
"18444": {
"url": "https://plugins.jetbrains.com/files/18444/163012/NetBeans6.5Keymap.zip",
"hash": "sha256-3oB+XuiQ2wxXSfl4aD3BVu/zucqtP9liFjkr9U7ITCU=",
"name": "netbeans-6-5-keymap",
"version": "221.5080.20"
}
}
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 7f673bc

Please sign in to comment.