From 6f513658ffe3a4ce2c60b0935ae8cc79cdd2a006 Mon Sep 17 00:00:00 2001 From: Matthieu Daniel-Thomas Date: Thu, 7 Nov 2024 09:20:58 +0100 Subject: [PATCH] phoebus-client: add a wrapper The wrapper was added for edit JAVA_OPTS in options. --- pkgs/default.nix | 1 + .../phoebus/client-unwrapped/default.nix | 94 +++++++++++ .../fix-python-path.patch | 0 pkgs/epnix/tools/phoebus/client/default.nix | 159 ++++++------------ .../tools/phoebus/setup-hook/setup-hook.sh | 2 + 5 files changed, 148 insertions(+), 108 deletions(-) create mode 100644 pkgs/epnix/tools/phoebus/client-unwrapped/default.nix rename pkgs/epnix/tools/phoebus/{client => client-unwrapped}/fix-python-path.patch (100%) diff --git a/pkgs/default.nix b/pkgs/default.nix index 295b3041..0328d645 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -82,6 +82,7 @@ in pcas = callPackage ./epnix/tools/pcas {}; phoebus = callPackage ./epnix/tools/phoebus/client {}; + phoebus-unwrapped = callPackage ./epnix/tools/phoebus/client-unwrapped {}; phoebus-alarm-server = callPackage ./epnix/tools/phoebus/alarm-server {}; phoebus-alarm-logger = callPackage ./epnix/tools/phoebus/alarm-logger {}; phoebus-archive-engine = callPackage ./epnix/tools/phoebus/archive-engine {}; diff --git a/pkgs/epnix/tools/phoebus/client-unwrapped/default.nix b/pkgs/epnix/tools/phoebus/client-unwrapped/default.nix new file mode 100644 index 00000000..fe2e22f2 --- /dev/null +++ b/pkgs/epnix/tools/phoebus/client-unwrapped/default.nix @@ -0,0 +1,94 @@ +{ + lib, + epnixLib, + stdenv, + substituteAll, + maven, + makeWrapper, + makeDesktopItem, + copyDesktopItems, + epnix, + jdk, + openjfx, + python3, +}: let + buildDate = "2022-02-24T07:56:00Z"; +in + stdenv.mkDerivation { + pname = "phoebus-unwrapped"; + inherit (epnix.phoebus-deps) version src; + + patches = [ + (substituteAll { + src = ./fix-python-path.patch; + python = lib.getExe python3; + }) + ]; + + # TODO: make a scope, so that we don't pass around the whole `epnix` + nativeBuildInputs = [ + maven + copyDesktopItems + makeWrapper + (epnix.phoebus-setup-hook.override {jdk = jdk.override {enableJavaFX = true;};}) + (epnix.phoebus-setup-hook.override { + jdk = jdk.override { + enableJavaFX = true; + openjfx = openjfx.override { + withWebKit = true; + }; + }; + }) + ]; + + # Put runtime dependencies in propagated + # because references get thrown into a jar + # which is compressed, + # so the Nix scanner won't always be able to see them + propagatedBuildInputs = [ + python3 + ]; + + buildPhase = '' + runHook preBuild + + # Copy deps to a writable directory, due to the usage of "install-jars" + local deps=$PWD/deps + cp -r --no-preserve=mode "${epnix.phoebus-deps}" $deps + + # TODO: tests fail + mvn package \ + --projects "./phoebus-product" \ + --also-make \ + --offline \ + -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -DskipTests \ + -Dproject.build.outputTimestamp=${buildDate} \ + -Dmaven.repo.local="$deps" + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + installPhoebusJar \ + "phoebus-product/" \ + "product-$version.jar" \ + "phoebus" \ + "org.phoebus.product.Launcher" + + # MIME types for PV Tables + install -D -m 444 phoebus-product/phoebus.xml -t $out/share/mime/packages + + runHook postInstall + ''; + + meta = { + description = "Control System Studio's Phoebus client"; + homepage = "https://control-system-studio.readthedocs.io/en/latest/index.html"; + mainProgram = "phoebus"; + license = lib.licenses.epl10; + maintainers = with epnixLib.maintainers; [minijackson]; + inherit (jdk.meta) platforms; + }; + } diff --git a/pkgs/epnix/tools/phoebus/client/fix-python-path.patch b/pkgs/epnix/tools/phoebus/client-unwrapped/fix-python-path.patch similarity index 100% rename from pkgs/epnix/tools/phoebus/client/fix-python-path.patch rename to pkgs/epnix/tools/phoebus/client-unwrapped/fix-python-path.patch diff --git a/pkgs/epnix/tools/phoebus/client/default.nix b/pkgs/epnix/tools/phoebus/client/default.nix index 5913b22c..be1dbf46 100644 --- a/pkgs/epnix/tools/phoebus/client/default.nix +++ b/pkgs/epnix/tools/phoebus/client/default.nix @@ -1,112 +1,55 @@ { - lib, - epnixLib, - stdenv, - substituteAll, - maven, makeWrapper, + epnix, + epnixLib, + lib, makeDesktopItem, copyDesktopItems, - epnix, - jdk, - openjfx, - python3, -}: let - buildDate = "2022-02-24T07:56:00Z"; -in - stdenv.mkDerivation { - pname = "phoebus"; - inherit (epnix.phoebus-deps) version src; - - patches = [ - (substituteAll { - src = ./fix-python-path.patch; - python = lib.getExe python3; - }) - ]; - - # TODO: make a scope, so that we don't pass around the whole `epnix` - nativeBuildInputs = [ - maven - copyDesktopItems - makeWrapper - (epnix.phoebus-setup-hook.override {jdk = jdk.override {enableJavaFX = true;};}) - (epnix.phoebus-setup-hook.override { - jdk = jdk.override { - enableJavaFX = true; - openjfx = openjfx.override { - withWebKit = true; - }; - }; - }) - ]; - - # Put runtime dependencies in propagated - # because references get thrown into a jar - # which is compressed, - # so the Nix scanner won't always be able to see them - propagatedBuildInputs = [ - python3 - ]; - - desktopItems = [ - (makeDesktopItem { - name = "phoebus"; - exec = "phoebus -server 4918 -resource %f"; - desktopName = "Phoebus"; - keywords = ["epics" "css"]; - # https://specifications.freedesktop.org/menu-spec/menu-spec-1.0.html#category-registry - categories = [ - # Main - "Office" - - # Additional - "Java" - "Viewer" - ]; - }) - ]; - - buildPhase = '' - runHook preBuild - - # Copy deps to a writable directory, due to the usage of "install-jars" - local deps=$PWD/deps - cp -r --no-preserve=mode "${epnix.phoebus-deps}" $deps - - # TODO: tests fail - mvn package \ - --projects "./phoebus-product" \ - --also-make \ - --offline \ - -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -DskipTests \ - -Dproject.build.outputTimestamp=${buildDate} \ - -Dmaven.repo.local="$deps" - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - installPhoebusJar \ - "phoebus-product/" \ - "product-$version.jar" \ - "phoebus" \ - "org.phoebus.product.Launcher" - - # MIME types for PV Tables - install -D -m 444 phoebus-product/phoebus.xml -t $out/share/mime/packages - - runHook postInstall - ''; - - meta = { - description = "Control System Studio's Phoebus client"; - homepage = "https://control-system-studio.readthedocs.io/en/latest/index.html"; - mainProgram = "phoebus"; - license = lib.licenses.epl10; - maintainers = with epnixLib.maintainers; [minijackson]; - inherit (jdk.meta) platforms; - }; - } + stdenv, + java_opts ? "-XX:MinHeapSize=128m -XX:MaxHeapSize=4g -XX:InitialHeapSize=1g -XX:MaxHeapFreeRatio=10 -XX:MinHeapFreeRatio=5 -XX:-ShrinkHeapInSteps -XX:NativeMemoryTracking=detail", +}: +stdenv.mkDerivation { + pname = "phoebus"; + name = "phoebus"; + nativeBuildInputs = [makeWrapper copyDesktopItems]; + dontBuild = true; + dontConfigure = true; + dontUnpack = true; + + installPhase = '' + + runHook preInstall + # This wrapper for the `phoebus-unwrapped` executable sets the `JAVA_OPTS` + #environment variable with the provided `java_opts` value. + + makeWrapper "${lib.getExe epnix.phoebus-unwrapped}" "$out/bin/$name" \ + --prefix JAVA_OPTS ":" "${java_opts}" + runHook postInstall + ''; + + desktopItems = [ + (makeDesktopItem { + name = "phoebus"; + exec = "phoebus -server 4918 -resource %f"; + desktopName = "Phoebus"; + keywords = ["epics" "css"]; + # https://specifications.freedesktop.org/menu-spec/menu-spec-1.0.html#category-registry + categories = [ + # Main + "Office" + + # Additional + "Java" + "Viewer" + ]; + }) + ]; + meta = { + inherit (epnix.phoebus-unwrapped.meta) description; + inherit (epnix.phoebus-unwrapped.meta) homepage; + inherit (epnix.phoebus-unwrapped.meta) platforms; + inherit (epnix.phoebus-unwrapped.meta) license; + inherit (epnix.phoebus-unwrapped.meta) maintainers; + inherit (epnix.phoebus-unwrapped.meta) mainProgram; + }; +} diff --git a/pkgs/epnix/tools/phoebus/setup-hook/setup-hook.sh b/pkgs/epnix/tools/phoebus/setup-hook/setup-hook.sh index ad375576..5cd4a16f 100644 --- a/pkgs/epnix/tools/phoebus/setup-hook/setup-hook.sh +++ b/pkgs/epnix/tools/phoebus/setup-hook/setup-hook.sh @@ -1,11 +1,13 @@ # shellcheck shell=bash + installPhoebusJar() { local path="$1" local jarName="$2" local name="$3" local mainClass="$4" + mkdir -p "$out/share/java" local jarDeps=("$path"/target/lib/*.jar)