#
# Switches the JetBrains tools to use a Java with
# Wayland support hacked in.
#
# vim: et:ts=2:sw=2:
#
{ jdk, pkgs, ... }:
let
  
  # Helper that creates a modded jetbrains tool.
  overrideJdk = tool: tool.override { jdk = jdk; };
  mkJetbrainsTool = tool: (overrideJdk tool).overrideAttrs (prev: {

    # HACK: add in our wayland flags
    installPhase = pkgs.lib.replaceStrings 
      ["--set-default JDK_HOME"] 
      ["--add-flags '-Dawt.toolkit.name=WLToolkit' --set-default JDK_HOME"] 
      prev.installPhase;

    # HACK: you're not free enough, yet
    meta.license.free = true;

  });
in 
  with pkgs.jetbrains;

# Note that this is very deliberately missing a bunch of tools!
# That's to make sure if we add one to our packages, it errors
# instead of giving us the unwrapped one.
{
  clion = mkJetbrainsTool clion;
  idea-ultimate = mkJetbrainsTool idea-ultimate;
  pycharm-professional = mkJetbrainsTool pycharm-professional;
  writerside = mkJetbrainsTool writerside;
  webstorm = mkJetbrainsTool webstorm;
  rust-rover = mkJetbrainsTool rust-rover;
}
