Skip to content

Commit

Permalink
signald: convert to gradle setup hook
Browse files Browse the repository at this point in the history
  • Loading branch information
chayleaf committed Dec 10, 2023
1 parent c145324 commit cd5e909
Show file tree
Hide file tree
Showing 4 changed files with 732 additions and 183 deletions.

This file was deleted.

This file was deleted.

87 changes: 17 additions & 70 deletions pkgs/applications/networking/instant-messengers/signald/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{ lib, stdenv, fetchurl, fetchFromGitLab, jdk17_headless, coreutils, gradle, git, perl
, makeWrapper, fetchpatch, substituteAll, jre_minimal
{ lib, stdenv, fetchFromGitLab, jdk17_headless, coreutils, gradle, git
, makeWrapper, jre_minimal
}:

# NOTE: when updating the package, please check if some of the hacks in `deps.installPhase`
# can be removed again!

let
pname = "signald";
version = "0.23.2";
Expand Down Expand Up @@ -35,76 +32,16 @@ let
];
};

# fake build to pre-download deps into fixed-output derivation
deps = stdenv.mkDerivation {
pname = "${pname}-deps";
inherit src version;
nativeBuildInputs = [ gradle perl ];
patches = [ ./0001-Fetch-buildconfig-during-gradle-build-inside-Nix-FOD.patch ];
buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
gradle --no-daemon build
'';
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 -x
# WARNING: don't try this at home and wear safety-goggles while working with this!
# We patch around in the dependency tree to resolve some spurious dependency resolution errors.
# Whenever this package gets updated, please check if some of these hacks are obsolete!
# Mimic existence of okio-3.2.0.jar. Originally known as okio-jvm-3.2.0 (and renamed),
# but gradle doesn't detect such renames, only fetches the latter and then fails
# in `signald.buildPhase` because it cannot find `okio-3.2.0.jar`.
pushd $out/com/squareup/okio/okio/3.2.0 &>/dev/null
cp -v ../../okio-jvm/3.2.0/okio-jvm-3.2.0.jar okio-3.2.0.jar
popd &>/dev/null
# For some reason gradle fetches 2.14.1 instead of 2.14.0 here even though 2.14.0 is required
# according to `./gradlew -q dependencies`, so we pretend to have 2.14.0 available here.
# According to the diff in https://github.com/FasterXML/jackson-dataformats-text/compare/jackson-dataformats-text-2.14.0...jackson-dataformats-text-2.14.1
# the only relevant change is in the code itself (and in the tests/docs), so this seems
# binary-compatible.
cp -v \
$out/com/fasterxml/jackson/dataformat/jackson-dataformat-toml/2.14.1/jackson-dataformat-toml-2.14.1.jar \
$out/com/fasterxml/jackson/dataformat/jackson-dataformat-toml/2.14.0/jackson-dataformat-toml-2.14.0.jar
'';
# Don't move info to share/
forceShare = [ "dummy" ];
outputHashAlgo = "sha256";
outputHashMode = "recursive";
# Downloaded jars differ by platform
outputHash = {
x86_64-linux = "sha256-9DHykkvazVBN2kfw1Pbejizk/R18v5w8lRBHZ4aXL5Q=";
aarch64-linux = "sha256-RgAiRbUojBc+9RN/HpAzzpTjkjZ6q+jebDsqvah5XBw=";
}.${stdenv.system} or (throw "Unsupported platform");
};

in stdenv.mkDerivation {
inherit pname src version;

patches = [
(substituteAll {
src = ./0002-buildconfig-local-deps-fixes.patch;
inherit deps;
})
];

passthru = {
# Mostly for debugging purposes.
inherit deps;
mitmCache = gradle.fetchDeps {
name = "${pname}-deps";
data = ./deps.json;
};

buildPhase = ''
runHook preBuild
export GRADLE_USER_HOME=$(mktemp -d)
gradle --offline --no-daemon distTar
runHook postBuild
'';
gradleBuildTask = "distTar";

installPhase = ''
runHook preInstall
Expand All @@ -122,6 +59,16 @@ in stdenv.mkDerivation {

doCheck = true;

passthru.updateDeps = gradle.updateDeps {
attrPath = pname;
gradleCommands = ''
SIGNALD_TARGET=x86_64-unknown-linux-gnu gradle nixSupport_downloadDeps
SIGNALD_TARGET=aarch64-unknown-linux-gnu gradle nixSupport_downloadDeps
SIGNALD_TARGET=x86_64-apple-darwin gradle nixSupport_downloadDeps
SIGNALD_TARGET=aarch64-apple-darwin gradle nixSupport_downloadDeps
'';
};

meta = with lib; {
description = "Unofficial daemon for interacting with Signal";
longDescription = ''
Expand All @@ -136,6 +83,6 @@ in stdenv.mkDerivation {
];
license = licenses.gpl3Plus;
maintainers = with maintainers; [ expipiplus1 ma27 ];
platforms = [ "x86_64-linux" "aarch64-linux" ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
};
}
Loading

0 comments on commit cd5e909

Please sign in to comment.