nur-packages/pkgs/applications/editors/jetbrains/wrapper.nix

50 lines
1.1 KiB
Nix
Raw Normal View History

{ lib, makeWrapper, runCommand }: self:
2020-10-15 19:05:13 +11:00
with lib;
package:
pluginsFun:
let
plugins =
if isFunction pluginsFun
then pluginsFun self
else pluginsFun;
# FIXME: Is this still needed?
2020-10-15 19:05:13 +11:00
info = builtins.parseDrvName package.name;
badPlugins = filter (p: ! elem info.name p.jetbrainsPlatforms) plugins;
errorMsg = "plugins [ ${toString (map (p: p.name) badPlugins)} ] are not available for platform ${info.name}";
in
assert assertMsg (length badPlugins == 0) errorMsg;
runCommand
(appendToName "with-plugins" package).name
{
nativeBuildInputs = [ package makeWrapper ];
inherit package plugins;
packageName = package.name;
preferLocalBuild = true;
allowSubstitutes = false;
} ''
mkdir -p $out/$packageName/plugins
for dir in $package/*; do
cp -r $dir $out/
done
# Install plugins
for plugin in $plugins; do
local pluginName=$(basename $plugin)
pluginName=''${pluginName#*-}
pluginName=''${pluginName%-([0-9].)*}
ln -s $plugin $out/$packageName/plugins/$pluginName
done
# Fix up wrapper
substituteInPlace $out/bin/* \
--replace "$package" "$out"
''