100 lines
2.5 KiB
Nix
100 lines
2.5 KiB
Nix
{ stdenv, runtimeShell, fetchFromGitHub, makeWrapper, openjdk17, gradle, perl
|
|
, writeText }:
|
|
let
|
|
meta = builtins.fromJSON (builtins.readFile ../meta.json);
|
|
|
|
pname = "piped-backend";
|
|
rev = "${meta.backend.rev}";
|
|
version = "latest-${rev}";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "TeamPiped";
|
|
repo = "Piped-Backend";
|
|
inherit rev;
|
|
sha256 = "${meta.backend.sha256}";
|
|
};
|
|
|
|
deps = stdenv.mkDerivation {
|
|
pname = "${pname}-deps";
|
|
inherit src version;
|
|
nativeBuildInputs = [ gradle openjdk17 perl ];
|
|
|
|
buildPhase = ''
|
|
export GRADLE_USER_HOME=$(mktemp -d);
|
|
gradle --no-daemon assemble shadowJar
|
|
'';
|
|
|
|
# perl code mavenizes paths (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
|
|
installPhase = ''
|
|
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
|
|
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/$5" #e' \
|
|
| sh
|
|
'';
|
|
|
|
dontStrip = true;
|
|
|
|
outputHashAlgo = "sha256";
|
|
outputHashMode = "recursive";
|
|
outputHash = "sha256-fERSbMTJcvf1fG+H1yg2TFwdsq6+mkTzj/LvutgLAQs=";
|
|
};
|
|
|
|
gradleInit = writeText "init.gradle" ''
|
|
logger.lifecycle 'Replacing Maven repositories with ${deps}...'
|
|
gradle.projectsLoaded {
|
|
rootProject.allprojects {
|
|
buildscript {
|
|
repositories {
|
|
clear()
|
|
maven { url '${deps}' }
|
|
}
|
|
}
|
|
repositories {
|
|
clear()
|
|
maven { url '${deps}' }
|
|
}
|
|
}
|
|
}
|
|
settingsEvaluated { settings ->
|
|
settings.pluginManagement {
|
|
repositories {
|
|
maven { url '${deps}' }
|
|
}
|
|
}
|
|
}
|
|
'';
|
|
|
|
in stdenv.mkDerivation rec {
|
|
inherit pname version src;
|
|
|
|
nativeBuildInputs = [ gradle openjdk17 ];
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
export GRADLE_USER_HOME=$(mktemp -d)
|
|
|
|
gradle --offline --init-script ${gradleInit} shadowJar
|
|
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
ls -R build
|
|
|
|
mkdir -p "$out/share/piped-backend"
|
|
cp build/libs/piped-1.0-all.jar "$out/share/piped-backend"
|
|
|
|
mkdir -p "$out/bin"
|
|
cat <<EOF >$out/bin/piped-backend
|
|
#!${runtimeShell}
|
|
export JAVA_HOME=${openjdk17}
|
|
exec ${openjdk17}/bin/java -jar "$out/share/piped-backend/piped-1.0-all.jar" "\$@"
|
|
EOF
|
|
chmod a+x "$out/bin/piped-backend"
|
|
|
|
runHook postInstall
|
|
'';
|
|
}
|