{ stdenv , fetchzip , fetchurl , fetchFromGitHub , lib , gradle , perl , makeWrapper , openjdk11 , unzip , makeDesktopItem , autoPatchelfHook , icoutils , xcbuild , protobuf3_17 , libredirect }: let pkg_path = "$out/lib/ghidra"; pname = "ghidra"; version = "10.1.1"; src = fetchFromGitHub { owner = "NationalSecurityAgency"; repo = "Ghidra"; rev = "Ghidra_${version}_build"; sha256 = "sha256-0hj9IVvTxgStCbfnTzqeKD+Q5GnGowDsIkMvk2GqJqY="; }; desktopItem = makeDesktopItem { name = "ghidra"; exec = "ghidra"; icon = "ghidra"; desktopName = "Ghidra"; genericName = "Ghidra Software Reverse Engineering Suite"; categories = "Development;"; }; # postPatch scripts. # Tells ghidra to use our own protoc binary instead of the prebuilt one. fixProtoc = '' cat >>Ghidra/Debug/Debugger-gadp/build.gradle <>build.gradle < subProject.buildscript.configurations.each { configuration -> resolveConfiguration(subProject, configuration, "buildscript config \''${configuration.name}") } subProject.configurations.each { configuration -> resolveConfiguration(subProject, configuration, "config \''${configuration.name}") } } } } void resolveConfiguration(subProject, configuration, name) { if (configuration.canBeResolved) { logger.info("Resolving project {} {}", subProject.name, name) configuration.resolve() } } HERE ''; # fake build to pre-download deps into fixed-output derivation # Taken from mindustry derivation. deps = stdenv.mkDerivation { pname = "${pname}-deps"; inherit version src; patches = [ ./0001-Use-protobuf-gradle-plugin.patch ]; postPatch = fixProtoc + addResolveStep; nativeBuildInputs = [ gradle perl ] ++ lib.optional stdenv.isDarwin xcbuild; buildPhase = '' export GRADLE_USER_HOME=$(mktemp -d) # First, fetch the static dependencies. gradle --no-daemon --info -Dorg.gradle.java.home=${openjdk11} -I gradle/support/fetchDependencies.gradle init # Then, fetch the maven dependencies. gradle --no-daemon --info -Dorg.gradle.java.home=${openjdk11} resolveDependencies ''; # perl code mavenizes pathes (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/maven/$x/$3/$4/$5" #e' \ | sh cp -r dependencies $out/dependencies ''; outputHashAlgo = "sha256"; outputHashMode = "recursive"; outputHash = "sha256-Yxf6g908+fRRUh40PrwNUCTvxzlvSmwzE8R+3ZkRIvs="; }; in stdenv.mkDerivation rec { inherit pname version src; nativeBuildInputs = [ gradle unzip makeWrapper icoutils ] ++ lib.optional stdenv.isDarwin xcbuild; dontStrip = true; patches = [ ./0001-Use-protobuf-gradle-plugin.patch ]; postPatch = fixProtoc; buildPhase = (lib.optionalString stdenv.isDarwin '' export HOME=$(mktemp -d) # construct a dummy /etc/passwd file - something attempts to determine # the user's "real" home using this DUMMY_PASSWD=$(realpath ../dummy-passwd) cat > $DUMMY_PASSWD <