depot/nix/pkgs/unifi-hack/default.nix

49 lines
1.5 KiB
Nix
Raw Permalink Normal View History

{ depot, pkgs, ... }:
let
inherit (pkgs) stdenvNoCC jdk aspectj unifi;
in
stdenvNoCC.mkDerivation {
pname = "unifi-hack";
version = "depot";
src = ./aspect;
nativeBuildInputs = [ jdk aspectj depot.pkgs.tiny-remapper ];
buildPhase = ''
mkdir $NIX_BUILD_TOP/tmp
cp $(type -p ajc) $NIX_BUILD_TOP/tmp/ajc
substituteInPlace $NIX_BUILD_TOP/tmp/ajc \
--replace '-Xmx64M' ""
ajc_classpath="$(ls ${unifi}/lib/*.jar | tr '\n' ':' | sed 's/:$//')"
tiny-remapper ${unifi}/lib/ace.jar $NIX_BUILD_TOP/tmp/acedeobf.jar ./ace.jar.tiny2map intermediary named
$NIX_BUILD_TOP/tmp/ajc -8 \
-classpath "${aspectj}/lib/aspectjrt.jar:$ajc_classpath" \
-inpath $NIX_BUILD_TOP/tmp/acedeobf.jar \
-outjar $NIX_BUILD_TOP/tmp/aceaspected.jar \
./MyLogin.aj
tiny-remapper $NIX_BUILD_TOP/tmp/aceaspected.jar $NIX_BUILD_TOP/tmp/acereobf.jar ./ace.jar.tiny2map named intermediary
# Repack the manifest
pushd $NIX_BUILD_TOP/tmp
jar xf acereobf.jar META-INF/MANIFEST.MF
awk \
'/^[^ ]/ { inclasspath=0 } /Class-Path:/ { inclasspath=1 } { if (inclasspath) print; }' \
META-INF/MANIFEST.MF > classpath.MF
substituteInPlace classpath.MF \
--replace 'Class-Path: ' 'Class-Path: aspectjrt.jar '
jar -ufm acereobf.jar classpath.MF
popd
'';
installPhase = ''
cp -R ${unifi} $out
chmod -R u+w $out
rm $out/lib/ace.jar
cp $NIX_BUILD_TOP/tmp/acereobf.jar $out/lib/ace.jar
cp ${aspectj}/lib/aspectjrt.jar $out/lib/aspectjrt.jar
'';
}