1
0
Fork 0
piped-flake/packages/backend/default.nix

85 lines
1.8 KiB
Nix
Raw Permalink Normal View History

2023-09-08 10:59:27 +01:00
{
stdenv,
runtimeShell,
fetchFromGitHub,
jdk,
jre,
gradle,
perl,
writeText,
callPackage,
2023-09-21 01:24:37 +01:00
piped-backend-deps,
2023-09-08 10:59:27 +01:00
}: let
meta = builtins.fromJSON (builtins.readFile ../../meta.json);
2023-09-21 01:24:37 +01:00
deps = piped-backend-deps;
2023-09-08 10:59:27 +01:00
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 {
pname = "piped-backend";
version = "latest-${meta.backend.rev}";
src = fetchFromGitHub {
owner = "TeamPiped";
repo = "Piped-Backend";
rev = "${meta.backend.rev}";
sha256 = "${meta.backend.sha256}";
};
nativeBuildInputs = [gradle jdk];
buildPhase = ''
runHook preBuild
export JAVA_HOME=${jdk}
export GRADLE_USER_HOME=$(mktemp -d)
gradle -P org.gradle.java.installations.fromEnv=JAVA_HOME --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=${jre}
exec ${jre}/bin/java -jar "$out/share/piped-backend/piped-1.0-all.jar" "\$@"
EOF
chmod a+x "$out/bin/piped-backend"
runHook postInstall
'';
}