From d851231ee997d86335b75906473aeda9ce0fd24f Mon Sep 17 00:00:00 2001 From: xeals Date: Mon, 19 Oct 2020 19:11:26 +1100 Subject: [PATCH] jetbrains: update IDEA for generated plugins --- .../editors/jetbrains/common-plugins.nix | 2 +- .../editors/jetbrains/idea-plugins.nix | 9 +- .../editors/jetbrains/wrapper.nix | 8 +- pkgs/build-support/jetbrains/plugin-old.nix | 33 ++++++++ pkgs/build-support/jetbrains/plugin.nix | 82 ++++++++++++++----- pkgs/top-level/jetbrains-plugins.nix | 2 +- 6 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 pkgs/build-support/jetbrains/plugin-old.nix diff --git a/pkgs/applications/editors/jetbrains/common-plugins.nix b/pkgs/applications/editors/jetbrains/common-plugins.nix index 734055c..5ad91cf 100644 --- a/pkgs/applications/editors/jetbrains/common-plugins.nix +++ b/pkgs/applications/editors/jetbrains/common-plugins.nix @@ -4,7 +4,7 @@ self: let - commonBuild = import ../../../build-support/jetbrains/plugin.nix { + commonBuild = import ../../../build-support/jetbrains/plugin-old.nix { inherit lib stdenv fetchzip; jetbrainsPlatforms = [ "clion" diff --git a/pkgs/applications/editors/jetbrains/idea-plugins.nix b/pkgs/applications/editors/jetbrains/idea-plugins.nix index 33188ec..b5fc0c3 100644 --- a/pkgs/applications/editors/jetbrains/idea-plugins.nix +++ b/pkgs/applications/editors/jetbrains/idea-plugins.nix @@ -1,19 +1,19 @@ -{ lib, stdenv, fetchzip }: +{ lib, stdenv, variant }: self: let ideaBuild = import ../../../build-support/jetbrains/plugin.nix { - inherit lib stdenv fetchzip; + inherit lib stdenv variant; jetbrainsPlatforms = [ "idea-community" "idea-ultimate" ]; }; generateIdea = lib.makeOverridable ({ - idea ? ./manual-idea-packages.nix + generated ? ./idea-generated.nix }: let - imported = import idea { + imported = import generated { inherit (self) callPackage; }; @@ -26,4 +26,3 @@ let in ideaPlugins // { inherit ideaBuild; }); in generateIdea { } - diff --git a/pkgs/applications/editors/jetbrains/wrapper.nix b/pkgs/applications/editors/jetbrains/wrapper.nix index fa59585..4c50a4d 100644 --- a/pkgs/applications/editors/jetbrains/wrapper.nix +++ b/pkgs/applications/editors/jetbrains/wrapper.nix @@ -21,11 +21,13 @@ in assert assertMsg (length badPlugins == 0) errorMsg; appendToName "with-plugins" (package.overrideAttrs (oldAttrs: { - passthru = { inherit plugins; }; - # TODO: Purely aesthetics, but link the plugin to its name instead of hash-name-version + inherit plugins; + # TODO: Remove version from directory name installPhase = oldAttrs.installPhase + '' for plugin in $plugins; do - ln -s "$plugin" "$out/$name/plugins/$(basename $plugin)" + local dirname=$(basename "$plugin") + dirname=''${dirname:33} + ln -s "$plugin" "$out/$name/plugins/$dirname" done ''; })) diff --git a/pkgs/build-support/jetbrains/plugin-old.nix b/pkgs/build-support/jetbrains/plugin-old.nix new file mode 100644 index 0000000..82f8ff5 --- /dev/null +++ b/pkgs/build-support/jetbrains/plugin-old.nix @@ -0,0 +1,33 @@ +{ lib +, stdenv +, fetchzip +, jetbrainsPlatforms +}: + +{ pluginId +, pname +, version +, versionId +, sha256 +, filename ? "${pname}-${version}.zip" +}: + +stdenv.mkDerivation { + inherit pname version; + + src = fetchzip { + inherit sha256; + url = "https://plugins.jetbrains.com/files/${toString pluginId}/${toString versionId}/${filename}"; + }; + + passthru = { inherit jetbrainsPlatforms; }; + + installPhase = '' + mkdir $out + cp -r * $out/ + ''; + + meta = { + homepage = "https://plugins.jetbrains.com/plugin/${pluginId}-${lib.toLower pname}"; + }; +} diff --git a/pkgs/build-support/jetbrains/plugin.nix b/pkgs/build-support/jetbrains/plugin.nix index 82f8ff5..ccd1a29 100644 --- a/pkgs/build-support/jetbrains/plugin.nix +++ b/pkgs/build-support/jetbrains/plugin.nix @@ -1,33 +1,71 @@ { lib , stdenv -, fetchzip +, variant , jetbrainsPlatforms }: -{ pluginId -, pname -, version -, versionId -, sha256 -, filename ? "${pname}-${version}.zip" -}: +with lib; -stdenv.mkDerivation { +{ pname +, version + +, plugname +, plugid + +, buildInputs ? [] +, packageRequires ? [] +, meta ? {} + +, ... +}@args: + +let + + defaultMeta = { + broken = false; + platforms = variant.meta.platforms; + } // optionalAttrs ((args.src.meta.homepage or "") != "") { + homepage = args.src.meta.homepage; + } // optionalAttrs ((args.src.meta.description or "") != "") { + description = args.src.meta.description; + }; + +in + +stdenv.mkDerivation ({ inherit pname version; - src = fetchzip { - inherit sha256; - url = "https://plugins.jetbrains.com/files/${toString pluginId}/${toString versionId}/${filename}"; - }; - - passthru = { inherit jetbrainsPlatforms; }; - - installPhase = '' - mkdir $out - cp -r * $out/ + unpackCmd = '' + case "$curSrc" in + *.jar) + # don't unpack; keep original source filename without the hash + local filename=$(basename "$curSrc") + filename="''${filename:33}" + cp $curSrc $filename + chmod +w $filename + sourceRoot="." + ;; + *) + _defaultUnpack "$curSrc" + ;; + esac ''; - meta = { - homepage = "https://plugins.jetbrains.com/plugin/${pluginId}-${lib.toLower pname}"; - }; + # FIXME: Entirely possible this isn't correct for niche plugins; + # at the very least there are some plugins that come with JS + installPhase = '' + mkdir -p "$out/lib" + find -iname '*.jar' -exec cp {} "$out/lib/" \; + ''; + + buildInputs = [ ] ++ packageRequires ++ buildInputs; + propagatedBuildInputs = packageRequires; + + passthru = { inherit jetbrainsPlatforms plugid plugname; }; + + doCheck = false; + + meta = defaultMeta // meta; } + +// removeAttrs args [ "buildInputs" "packageRequires" "meta" ]) diff --git a/pkgs/top-level/jetbrains-plugins.nix b/pkgs/top-level/jetbrains-plugins.nix index badfac5..85b6487 100644 --- a/pkgs/top-level/jetbrains-plugins.nix +++ b/pkgs/top-level/jetbrains-plugins.nix @@ -13,7 +13,7 @@ let }; mkIdeaPlugins = import ../applications/editors/jetbrains/idea-plugins.nix { - inherit lib stdenv fetchzip; + inherit lib stdenv variant; }; jetbrainsWithPlugins = import ../applications/editors/jetbrains/wrapper.nix {