Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phoebus-setup-hook: add java heap size and change encoding by default for phoebus #97

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ outputs

# Created by running NixOS tests in interactive mode
.nixos-test-history

#VScode extra files
*.code-workspace
1 change: 1 addition & 0 deletions nixos/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
./modules/channel-finder/service.nix
./modules/phoebus/alarm-logger.nix
./modules/phoebus/alarm-server.nix
./modules/phoebus/client.nix
./modules/phoebus/olog.nix
./modules/phoebus/save-and-restore.nix
]
27 changes: 27 additions & 0 deletions nixos/modules/phoebus/client.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
config,
lib,
epnix,
pkgs,
...
}: let
cfg = config.programs.phoebus-client;
pkg = pkgs.epnix.phoebus.override {java_opts = cfg.java_opts;};
in {
options.programs.phoebus-client = {
enable = lib.mkEnableOption ''Enable the Phoebus client'';
java_opts = lib.mkOption {
type = lib.types.str;
default = "-XX:MinHeapSize=128m -XX:MaxHeapSize=4g -XX:InitialHeapSize=1g -XX:MaxHeapFreeRatio=10 -XX:MinHeapFreeRatio=5 -XX:-ShrinkHeapInSteps -XX:NativeMemoryTracking=detail";
example = "-XX:MinHeapSize=128m -XX:MaxHeapSize=4g -XX:InitialHeapSize=1g";
description = ''
This wrapper for the `phoebus-unwrapped` executable sets the `JAVA_OPTS`
environment variable with the provided `java_opts` value.
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
'';
};
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [pkg];
};
}
1 change: 1 addition & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
94 changes: 94 additions & 0 deletions pkgs/epnix/tools/phoebus/client-unwrapped/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
lib,
epnixLib,
stdenv,
substituteAll,
maven,
makeWrapper,
makeDesktopItem,
copyDesktopItems,
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
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
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
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;
};
}
159 changes: 51 additions & 108 deletions pkgs/epnix/tools/phoebus/client/default.nix
Original file line number Diff line number Diff line change
@@ -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",
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
}:
stdenv.mkDerivation {
pname = "phoebus";
name = "phoebus";
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
nativeBuildInputs = [makeWrapper copyDesktopItems];
dontBuild = true;
dontConfigure = true;
dontUnpack = true;
Rider128 marked this conversation as resolved.
Show resolved Hide resolved

installPhase = ''

runHook preInstall
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
# 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
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
'';

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;
};
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions pkgs/epnix/tools/phoebus/setup-hook/setup-hook.sh
Rider128 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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)
Expand Down