3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/applications/editors/jetbrains/common.nix

97 lines
3.1 KiB
Nix
Raw Normal View History

{ stdenv, lib, makeDesktopItem, makeWrapper, patchelf, writeText
, coreutils, gnugrep, which, git, unzip, libsecret, libnotify, e2fsprogs
, vmopts ? null
}:
2016-01-15 17:18:54 +00:00
{ name, product, version, src, wmClass, jdk, meta, extraLdPath ? [], extraWrapperArgs ? [] }@args:
2016-01-15 17:18:54 +00:00
2021-01-15 13:21:58 +00:00
with lib;
2016-01-15 17:18:54 +00:00
let loName = toLower product;
hiName = toUpper product;
mainProgram = concatStringsSep "-" (init (splitString "-" name));
vmoptsName = loName
+ ( if (with stdenv.hostPlatform; (is32bit || isDarwin))
then ""
else "64" )
+ ".vmoptions";
2016-01-15 17:18:54 +00:00
in
2021-10-30 07:19:46 +01:00
with stdenv; lib.makeOverridable mkDerivation (rec {
2021-06-03 13:24:13 +01:00
inherit name src;
meta = args.meta // { inherit mainProgram; };
2021-06-03 13:24:13 +01:00
2016-01-15 17:18:54 +00:00
desktopItem = makeDesktopItem {
name = mainProgram;
exec = mainProgram;
2016-01-15 17:18:54 +00:00
comment = lib.replaceChars ["\n"] [" "] meta.longDescription;
desktopName = product;
genericName = meta.description;
categories = [ "Development" ];
icon = mainProgram;
startupWMClass = wmClass;
2016-01-15 17:18:54 +00:00
};
vmoptsFile = optionalString (vmopts != null) (writeText vmoptsName vmopts);
nativeBuildInputs = [ makeWrapper patchelf unzip ];
2016-01-15 17:18:54 +00:00
postPatch = lib.optionalString (!stdenv.isDarwin) ''
2016-01-15 17:18:54 +00:00
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.glibc.out}/lib/ld-linux*.so.2)
if [[ "${stdenv.hostPlatform.system}" == "x86_64-linux" && -e bin/fsnotifier64 ]]; then
2016-01-15 17:18:54 +00:00
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
'';
installPhase = ''
runHook preInstall
2016-01-15 17:18:54 +00:00
mkdir -p $out/{bin,$name,share/pixmaps,libexec/${name}}
cp -a . $out/$name
ln -s $out/$name/bin/${loName}.png $out/share/pixmaps/${mainProgram}.png
2016-01-15 17:18:54 +00:00
mv bin/fsnotifier* $out/libexec/${name}/.
jdk=${jdk.home}
item=${desktopItem}
makeWrapper "$out/$name/bin/${loName}.sh" "$out/bin/${mainProgram}" \
2021-01-15 13:21:58 +00:00
--prefix PATH : "$out/libexec/${name}:${lib.optionalString (stdenv.isDarwin) "${jdk}/jdk/Contents/Home/bin:"}${lib.makeBinPath [ jdk coreutils gnugrep which git ]}" \
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath ([
2017-04-01 09:48:52 +01:00
# Some internals want libstdc++.so.6
stdenv.cc.cc.lib libsecret e2fsprogs
libnotify
] ++ extraLdPath)}" \
${lib.concatStringsSep " " extraWrapperArgs} \
--set-default JDK_HOME "$jdk" \
--set-default ANDROID_JAVA_HOME "$jdk" \
--set-default JAVA_HOME "$jdk" \
2016-01-15 17:18:54 +00:00
--set ${hiName}_JDK "$jdk" \
--set ${hiName}_VM_OPTIONS ${vmoptsFile}
2016-01-15 17:18:54 +00:00
ln -s "$item/share/applications" $out/share
runHook postInstall
2016-01-15 17:18:54 +00:00
'';
2021-01-15 13:21:58 +00:00
} // lib.optionalAttrs (!(meta.license.free or true)) {
preferLocalBuild = true;
2021-10-30 07:19:46 +01:00
})