Skip to content

Commit

Permalink
Merge pull request #91 from minijackson/phoebus-olog-buildMaven
Browse files Browse the repository at this point in the history
phoebus-olog: build using buildMavenPackage function
  • Loading branch information
minijackson authored Jul 5, 2024
2 parents 8ff1d0f + 7e18ed0 commit 6c01b83
Showing 1 changed file with 46 additions and 97 deletions.
143 changes: 46 additions & 97 deletions pkgs/epnix/tools/phoebus/olog/default.nix
Original file line number Diff line number Diff line change
@@ -1,103 +1,52 @@
{
lib,
epnixLib,
stdenv,
fetchFromGitHub,
jre,
maven,
libfaketime,
canonicalize-jars-hook,
jdk,
git,
makeWrapper,
}: let
# TODO: upstream outputTimestamp
buildDate = "2022-02-24T07:56:00Z";
mvnOptions = "-Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pdeployable-jar -Dproject.build.outputTimestamp=${buildDate}";
in
stdenv.mkDerivation (final: {
pname = "phoebus-olog";
version = "4.7.3";

src = fetchFromGitHub {
owner = "Olog";
repo = "phoebus-olog";
rev = "v${final.version}";
hash = "sha256-WwRB4QtZBeH6GptTZJ02CBpP7BGzjZbwMYQrOmGevFo=";
};

deps = stdenv.mkDerivation {
name = with final; "${pname}-${version}-deps";
inherit (final) src;

nativeBuildInputs = [jdk maven git];

buildPhase = ''
runHook preBuild
# Don't use the launch script, we use the jar file as a jar
mvn package ${mvnOptions} -Dmaven.repo.local=$out
runHook postBuild
'';

# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with
# lastModified timestamps inside
installPhase = ''
runHook preInstall
find $out -type f \
-name \*.lastUpdated -or \
-name resolver-status.properties -or \
-name _remote.repositories \
-delete
runHook postInstall
'';

outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "sha256-40n06R2KBuuzqvVq1bWsd1jjQtcNQfK/4RbgtFmxTf8=";

doCheck = false;
};

nativeBuildInputs = [maven makeWrapper libfaketime];

buildPhase = ''
runHook preBuild
# Use faketime because files inside the jar have an mtime
faketime -f "1970-01-01 00:00:01" mvn package --offline ${mvnOptions} -Dmaven.repo.local="$deps"
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/share/java
jarName="service-olog-${final.version}.jar"
classpath=$(find $deps -name "*.jar" -printf ':%h/%f');
install -Dm644 target/service-olog-4.7.3.jar $out/share/java
# Strip the script at the beginning of the jar, so that we are able to
# canonicalize it
sed -i '1,/^exit 0$/d' $out/share/java/$jarName
makeWrapper ${jdk}/bin/java $out/bin/${final.pname} \
--add-flags "-classpath ''${classpath#:}" \
--add-flags "-jar $out/share/java/$jarName"
runHook postInstall
'';

meta = {
description = "Online logbook for experimental and industrial logging";
homepage = "https://olog.readthedocs.io/en/latest/";
license = lib.licenses.epl10;
maintainers = with epnixLib.maintainers; [minijackson];
inherit (jdk.meta) platforms;
};
})
}:
maven.buildMavenPackage rec {
pname = "phoebus-olog";
version = "4.7.3";

src = fetchFromGitHub {
owner = "Olog";
repo = "phoebus-olog";
rev = "v${version}";
hash = "sha256-WwRB4QtZBeH6GptTZJ02CBpP7BGzjZbwMYQrOmGevFo=";
};

mvnHash = "sha256-D1n5PfGulIgdjd60mChVLH1kQDOUcc/TvEw3oJUZ1h4=";
mvnParameters = "-Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Pdeployable-jar -Dproject.build.outputTimestamp=1980-01-01T00:00:02Z";

nativeBuildInputs = [makeWrapper];

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/share/java
jarName="service-olog-${version}.jar"
install -Dm644 target/service-olog-4.7.3.jar $out/share/java
# Strip the script at the beginning of the jar, so that we are able to
# canonicalize it
sed -i '1,/^exit 0$/d' $out/share/java/$jarName
makeWrapper ${lib.getExe jre} $out/bin/${meta.mainProgram} \
--add-flags "-jar $out/share/java/$jarName"
runHook postInstall
'';

meta = {
description = "Online logbook for experimental and industrial logging";
homepage = "https://olog.readthedocs.io/en/latest/";
mainProgram = "phoebus-olog";
license = lib.licenses.epl10;
maintainers = with epnixLib.maintainers; [minijackson];
inherit (jre.meta) platforms;
};
}

0 comments on commit 6c01b83

Please sign in to comment.