diff --git a/pkgs/applications/editors/jetbrains/builder/darwin.nix b/pkgs/applications/editors/jetbrains/builder/darwin.nix index d9250c686cbd2..cbff08c7a6063 100644 --- a/pkgs/applications/editors/jetbrains/builder/darwin.nix +++ b/pkgs/applications/editors/jetbrains/builder/darwin.nix @@ -1,57 +1,58 @@ # Darwin-specific base builder. -# TODO: -# This actually just ignores a lot of options passed to it... (e.g. buildInputs) -# - not entirely sure how this hasn't caused big problems yet. { lib, stdenvNoCC, undmg, - ... -}: -{ - meta, - pname, - product, - productShort, - src, - version, - passthru, - - plugins ? [ ], + excludeDrvArgNames, ... }: -let - loname = lib.toLower productShort; -in -stdenvNoCC.mkDerivation { - inherit - pname - src - version - plugins - passthru - ; - meta = meta // { - mainProgram = loname; - }; - desktopName = product; - dontFixup = true; - installPhase = '' - runHook preInstall - APP_DIR="$out/Applications/${product}.app" - mkdir -p "$APP_DIR" - cp -Tr *.app "$APP_DIR" - mkdir -p "$out/bin" - cat << EOF > "$out/bin/${loname}" - #!${stdenvNoCC.shell} - open -na '$APP_DIR' --args "\$@" - EOF - chmod +x "$out/bin/${loname}" - runHook postInstall - ''; - nativeBuildInputs = [ undmg ]; - sourceRoot = "."; +lib.extendMkDerivation { + inherit excludeDrvArgNames; + + constructDrv = stdenvNoCC.mkDerivation; + + extendDrvArgs = + finalAttrs: + { + product, + productShort ? product, + + nativeBuildInputs ? [ ], + meta ? { }, + ... + }: + + let + loname = lib.toLower productShort; + in + { + desktopName = product; + + dontFixup = true; + + installPhase = '' + runHook preInstall + APP_DIR="$out/Applications/${product}.app" + mkdir -p "$APP_DIR" + cp -Tr *.app "$APP_DIR" + mkdir -p "$out/bin" + cat << EOF > "$out/bin/${loname}" + #!${stdenvNoCC.shell} + open -na '$APP_DIR' --args "\$@" + EOF + chmod +x "$out/bin/${loname}" + runHook postInstall + ''; + + nativeBuildInputs = nativeBuildInputs ++ [ undmg ]; + + sourceRoot = "."; + + meta = meta // { + mainProgram = loname; + }; + }; } diff --git a/pkgs/applications/editors/jetbrains/builder/default.nix b/pkgs/applications/editors/jetbrains/builder/default.nix index 32787728e8030..b710bb9cc0d98 100644 --- a/pkgs/applications/editors/jetbrains/builder/default.nix +++ b/pkgs/applications/editors/jetbrains/builder/default.nix @@ -6,82 +6,64 @@ callPackage, jdk, - fontconfig, - libGL, - libX11, vmopts ? null, forceWayland ? false, }: let baseBuilder = if stdenv.hostPlatform.isDarwin then ./darwin.nix else ./linux.nix; - mkJetBrainsProductCore = callPackage baseBuilder { inherit vmopts; }; in # Makes a JetBrains IDE -{ - pname, - src, - version, - buildNumber, - wmClass, - product, - productShort ? product, - meta, - - libdbm, - fsnotifier, +lib.extendMkDerivation { + constructDrv = callPackage baseBuilder { + inherit vmopts jdk forceWayland; + # Args to not pass to mkDerivation in the base builders. Since both get the same args + # passed in, both have the same list of args to ignore, even if they don't both use + # all of them. + excludeDrvArgNames = [ + "product" + "productShort" + "buildNumber" + "wmClass" + "libdbm" + "fsnotifier" + "extraLdPath" + "extraWrapperArgs" + ]; + }; - extraWrapperArgs ? [ ], - extraLdPath ? [ ], - buildInputs ? [ ], - passthru ? { }, -}: -mkJetBrainsProductCore { - inherit - pname - extraLdPath - jdk - src - version - buildNumber - wmClass - product - productShort - libdbm - fsnotifier - ; + extendDrvArgs = + # NOTE: See linux.nix and darwin.nix for additional specific arguments + finalAttrs: + { + buildNumber, + product, - buildInputs = - buildInputs - ++ [ stdenv.cc.cc ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - fontconfig - libGL - libX11 - ]; + libdbm, + fsnotifier, - extraWrapperArgs = - extraWrapperArgs - ++ lib.optionals (stdenv.hostPlatform.isLinux && forceWayland) [ - ''--add-flags "\''${WAYLAND_DISPLAY:+-Dawt.toolkit.name=WLToolkit}"'' - ]; + meta ? { }, + passthru ? { }, + ... + }: + { + passthru = passthru // { + inherit + buildNumber + product + libdbm + fsnotifier + ; - passthru = lib.recursiveUpdate passthru { - inherit - buildNumber - product - libdbm - fsnotifier - ; + updateScript = ../updater/main.py; - updateScript = ../updater/main.py; + tests = { + plugins = callPackage ../plugins/tests.nix { ide = finalAttrs.finalPackage; }; + }; + }; - tests = { - plugins = callPackage ../plugins/tests.nix { ideName = pname; }; + meta = meta // { + teams = [ lib.teams.jetbrains ]; + }; }; - }; - - meta = meta // { - teams = [ lib.teams.jetbrains ]; - }; } diff --git a/pkgs/applications/editors/jetbrains/builder/linux.nix b/pkgs/applications/editors/jetbrains/builder/linux.nix index 22e2443e020b7..5194df00de233 100644 --- a/pkgs/applications/editors/jetbrains/builder/linux.nix +++ b/pkgs/applications/editors/jetbrains/builder/linux.nix @@ -18,163 +18,179 @@ e2fsprogs, python3, autoPatchelfHook, - vmopts ? null, glibcLocales, -}: + fontconfig, + libGL, + libX11, -{ - pname, - product, - productShort, - version, - src, - wmClass, jdk, - meta, - passthru, - - libdbm, - fsnotifier, - - extraLdPath ? [ ], - extraWrapperArgs ? [ ], - buildInputs ? [ ], - ... -}@args: - -let - loName = lib.toLower productShort; - hiName = lib.toUpper productShort; - vmoptsName = loName + lib.optionalString stdenv.hostPlatform.is64bit "64" + ".vmoptions"; -in - -with stdenv; -lib.makeOverridable mkDerivation ( - rec { - inherit - pname - version - src - buildInputs - passthru - ; - meta = args.meta // { - mainProgram = pname; - }; + vmopts ? null, + forceWayland ? null, + excludeDrvArgNames, +}: - desktopItem = makeDesktopItem { - name = pname; - exec = pname; - comment = lib.trim (lib.replaceString "\n" " " meta.longDescription); - desktopName = product; - genericName = meta.description; - categories = [ "Development" ]; - icon = pname; - startupWMClass = wmClass; - }; +lib.extendMkDerivation { + inherit excludeDrvArgNames; + + constructDrv = stdenv.mkDerivation; + + extendDrvArgs = + finalAttrs: + { + pname, + product, + productShort ? product, + wmClass, + + libdbm, + fsnotifier, + + extraLdPath ? [ ], + extraWrapperArgs ? [ ], + buildInputs ? [ ], + nativeBuildInputs ? [ ], + meta ? { }, + postPatch ? "", + ... + }: + + let + loName = lib.toLower productShort; + hiName = lib.toUpper productShort; + vmoptsName = loName + lib.optionalString stdenv.hostPlatform.is64bit "64" + ".vmoptions"; + finalExtraWrapperArgs = + extraWrapperArgs + ++ lib.optionals forceWayland [ + ''--add-flags "\''${WAYLAND_DISPLAY:+-Dawt.toolkit.name=WLToolkit}"'' + ]; + + desktopItem = makeDesktopItem { + name = finalAttrs.pname; + exec = finalAttrs.meta.mainProgram; + comment = lib.trim (lib.replaceString "\n" " " finalAttrs.meta.longDescription); + desktopName = product; + genericName = finalAttrs.meta.description; + categories = [ "Development" ]; + icon = pname; + startupWMClass = wmClass; + }; + + vmoptsIDE = if hiName == "WEBSTORM" then "WEBIDE" else hiName; + vmoptsFile = lib.optionalString (vmopts != null) (writeText vmoptsName vmopts); + in + { + inherit desktopItem vmoptsIDE vmoptsFile; + + buildInputs = buildInputs ++ [ + stdenv.cc.cc + fontconfig + libGL + libX11 + ]; + + nativeBuildInputs = nativeBuildInputs ++ [ + makeWrapper + patchelf + unzip + autoPatchelfHook + ]; + + postPatch = '' + rm -rf jbr + # When using the IDE as a remote backend using gateway, it expects the jbr directory to contain the jdk + ln -s ${jdk.home} jbr + + if [ -d "plugins/remote-dev-server" ]; then + patch -F3 -p1 < ${../patches/jetbrains-remote-dev.patch} + fi - vmoptsIDE = if hiName == "WEBSTORM" then "WEBIDE" else hiName; - vmoptsFile = lib.optionalString (vmopts != null) (writeText vmoptsName vmopts); + vmopts_file=bin/linux/${vmoptsName} + if [[ ! -f $vmopts_file ]]; then + vmopts_file=bin/${vmoptsName} + if [[ ! -f $vmopts_file ]]; then + echo "ERROR: $vmopts_file not found" + exit 1 + fi + fi + echo -Djna.library.path=${ + lib.makeLibraryPath [ + libsecret + e2fsprogs + libnotify + # Required for Help -> Collect Logs + # in at least rider and goland + udev + ] + } >> $vmopts_file + '' + + postPatch; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{bin,$pname,share/pixmaps,share/icons/hicolor/scalable/apps} + cp -a . $out/$pname + [[ -f $out/$pname/bin/${loName}.png ]] && ln -s $out/$pname/bin/${loName}.png $out/share/pixmaps/${pname}.png + [[ -f $out/$pname/bin/${loName}.svg ]] && ln -s $out/$pname/bin/${loName}.svg $out/share/pixmaps/${pname}.svg \ + && ln -s $out/$pname/bin/${loName}.svg $out/share/icons/hicolor/scalable/apps/${pname}.svg + cp ${libdbm}/lib/libdbm.so $out/$pname/bin/libdbm.so + cp ${fsnotifier}/bin/fsnotifier $out/$pname/bin/fsnotifier + + jdk=${jdk.home} + item=${desktopItem} + + needsWrapping=() + + if [ -f "$out/$pname/bin/${loName}" ]; then + needsWrapping+=("$out/$pname/bin/${loName}") + fi + if [ -f "$out/$pname/bin/${loName}.sh" ]; then + needsWrapping+=("$out/$pname/bin/${loName}.sh") + fi + + for launcher in "''${needsWrapping[@]}" + do + wrapProgram "$launcher" \ + --prefix PATH : "${ + lib.makeBinPath [ + jdk + coreutils + gnugrep + which + git + ] + }" \ + --suffix PATH : "${lib.makeBinPath [ python3 ]}" \ + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath extraLdPath}" \ + ${lib.concatStringsSep " " finalExtraWrapperArgs} \ + --set-default JDK_HOME "$jdk" \ + --set-default ANDROID_JAVA_HOME "$jdk" \ + --set-default JAVA_HOME "$jdk" \ + --set-default JETBRAINS_CLIENT_JDK "$jdk" \ + --set-default ${hiName}_JDK "$jdk" \ + --set-default LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive" \ + --set-default ${vmoptsIDE}_VM_OPTIONS ${vmoptsFile} + done + + launcher="$out/$pname/bin/${loName}" + if [ ! -e "$launcher" ]; then + launcher+=.sh + fi - nativeBuildInputs = [ - makeWrapper - patchelf - unzip - autoPatchelfHook - ]; + ln -s "$launcher" $out/bin/$pname + rm -rf $out/$pname/plugins/remote-dev-server/selfcontained/ + echo -e '#!/usr/bin/env bash\n'"$out/$pname/bin/remote-dev-server.sh"' "$@"' > $out/$pname/bin/remote-dev-server-wrapped.sh + chmod +x $out/$pname/bin/remote-dev-server-wrapped.sh + ln -s "$out/$pname/bin/remote-dev-server-wrapped.sh" $out/bin/$pname-remote-dev-server + ln -s "$item/share/applications" $out/share - postPatch = '' - rm -rf jbr - # When using the IDE as a remote backend using gateway, it expects the jbr directory to contain the jdk - ln -s ${jdk.home} jbr + runHook postInstall + ''; - if [ -d "plugins/remote-dev-server" ]; then - patch -F3 -p1 < ${../patches/jetbrains-remote-dev.patch} - fi + preferLocalBuild = !(finalAttrs.meta.license.free or true); - vmopts_file=bin/linux/${vmoptsName} - if [[ ! -f $vmopts_file ]]; then - vmopts_file=bin/${vmoptsName} - if [[ ! -f $vmopts_file ]]; then - echo "ERROR: $vmopts_file not found" - exit 1 - fi - fi - echo -Djna.library.path=${ - lib.makeLibraryPath [ - libsecret - e2fsprogs - libnotify - # Required for Help -> Collect Logs - # in at least rider and goland - udev - ] - } >> $vmopts_file - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out/{bin,$pname,share/pixmaps,share/icons/hicolor/scalable/apps} - cp -a . $out/$pname - [[ -f $out/$pname/bin/${loName}.png ]] && ln -s $out/$pname/bin/${loName}.png $out/share/pixmaps/${pname}.png - [[ -f $out/$pname/bin/${loName}.svg ]] && ln -s $out/$pname/bin/${loName}.svg $out/share/pixmaps/${pname}.svg \ - && ln -s $out/$pname/bin/${loName}.svg $out/share/icons/hicolor/scalable/apps/${pname}.svg - cp ${libdbm}/lib/libdbm.so $out/$pname/bin/libdbm.so - cp ${fsnotifier}/bin/fsnotifier $out/$pname/bin/fsnotifier - - jdk=${jdk.home} - item=${desktopItem} - - needsWrapping=() - - if [ -f "$out/$pname/bin/${loName}" ]; then - needsWrapping+=("$out/$pname/bin/${loName}") - fi - if [ -f "$out/$pname/bin/${loName}.sh" ]; then - needsWrapping+=("$out/$pname/bin/${loName}.sh") - fi - - for launcher in "''${needsWrapping[@]}" - do - wrapProgram "$launcher" \ - --prefix PATH : "${ - lib.makeBinPath [ - jdk - coreutils - gnugrep - which - git - ] - }" \ - --suffix PATH : "${lib.makeBinPath [ python3 ]}" \ - --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath extraLdPath}" \ - ${lib.concatStringsSep " " extraWrapperArgs} \ - --set-default JDK_HOME "$jdk" \ - --set-default ANDROID_JAVA_HOME "$jdk" \ - --set-default JAVA_HOME "$jdk" \ - --set-default JETBRAINS_CLIENT_JDK "$jdk" \ - --set-default ${hiName}_JDK "$jdk" \ - --set-default LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive" \ - --set-default ${vmoptsIDE}_VM_OPTIONS ${vmoptsFile} - done - - launcher="$out/$pname/bin/${loName}" - if [ ! -e "$launcher" ]; then - launcher+=.sh - fi - - ln -s "$launcher" $out/bin/$pname - rm -rf $out/$pname/plugins/remote-dev-server/selfcontained/ - echo -e '#!/usr/bin/env bash\n'"$out/$pname/bin/remote-dev-server.sh"' "$@"' > $out/$pname/bin/remote-dev-server-wrapped.sh - chmod +x $out/$pname/bin/remote-dev-server-wrapped.sh - ln -s "$out/$pname/bin/remote-dev-server-wrapped.sh" $out/bin/$pname-remote-dev-server - ln -s "$item/share/applications" $out/share - - runHook postInstall - ''; - } - // lib.optionalAttrs (!(meta.license.free or true)) { - preferLocalBuild = true; - } -) + meta = meta // { + mainProgram = pname; + }; + }; +} diff --git a/pkgs/applications/editors/jetbrains/ides/dataspell.nix b/pkgs/applications/editors/jetbrains/ides/dataspell.nix index 63fe6cd3541da..76a91b0962e20 100644 --- a/pkgs/applications/editors/jetbrains/ides/dataspell.nix +++ b/pkgs/applications/editors/jetbrains/ides/dataspell.nix @@ -47,7 +47,9 @@ mkJetBrainsProduct { src = fetchurl (urls.${system} or (throw "Unsupported system: ${system}")); - buildInputs = [ + # NOTE: This `lib.optionals` is only here because the old Darwin builder ignored `buildInputs`. + # DataSpell may need these, even on Darwin! + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ libgcc (runCommand "libR" { } '' mkdir -p $out/lib diff --git a/pkgs/applications/editors/jetbrains/plugins/tests.nix b/pkgs/applications/editors/jetbrains/plugins/tests.nix index 7f84beb2889e8..2f32829ecf733 100644 --- a/pkgs/applications/editors/jetbrains/plugins/tests.nix +++ b/pkgs/applications/editors/jetbrains/plugins/tests.nix @@ -6,12 +6,12 @@ fetchzip, fetchurl, # If not set, all IDEs are tested. - ideName ? null, + ide ? null, }: let ides = - if ideName == null then + if ide == null then with jetbrains; [ clion @@ -31,7 +31,7 @@ let webstorm ] else - [ (jetbrains.${ideName}) ]; + [ ide ]; in { # Check to see if the process for adding plugins is breaking anything, instead of the plugins themselves diff --git a/pkgs/applications/editors/jetbrains/readme.md b/pkgs/applications/editors/jetbrains/readme.md index b0919920d2e06..0ed0a67d4fd52 100644 --- a/pkgs/applications/editors/jetbrains/readme.md +++ b/pkgs/applications/editors/jetbrains/readme.md @@ -56,9 +56,6 @@ Any comments or other manual changes between these markers will be removed when - Add it to `default.nix` ### TODO: - - Switch `mkJetbrainsProduct` to use `lib.extendMkDerivation`, see also: - - https://github.com/NixOS/nixpkgs/pull/475183#discussion_r2655305961 - - https://github.com/NixOS/nixpkgs/pull/475183#discussion_r2655348886 - move PyCharm overrides to a common place outside of `default.nix` - package `patchSharedLibs` from `default.nix` as a hook - cleanup this TODO list, especially the following points, which have been here since 2023