Skip to content

Commit

Permalink
Merge pull request #207883 from nagy/freenet
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored Mar 19, 2023
2 parents 0bb4866 + 68cb767 commit 96f6f7c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 34 deletions.
123 changes: 90 additions & 33 deletions pkgs/applications/networking/p2p/freenet/default.nix
Original file line number Diff line number Diff line change
@@ -1,61 +1,118 @@
{ lib, stdenv, fetchurl, jdk, bash, coreutils, substituteAll, nixosTests, jna }:
{ lib, stdenv, fetchurl, fetchFromGitHub, jdk, gradle, bash, coreutils
, substituteAll, nixosTests, perl, fetchpatch, writeText }:

let
version = "build01494";
version = "01497";

freenet_ext = fetchurl {
url = "https://github.com/freenet/fred/releases/download/${version}/freenet-ext.jar";
url = "https://github.com/freenet/fred/releases/download/build01495/freenet-ext.jar";
sha256 = "sha256-MvKz1r7t9UE36i+aPr72dmbXafCWawjNF/19tZuk158=";
};
bcprov = fetchurl {
url = "https://github.com/freenet/fred/releases/download/${version}/bcprov-jdk15on-1.59.jar";
sha256 = "sha256-HDHkTjMdJeRtKTs+juLQcCimfbAR50yyRDKFrtHVnIU=";
};

seednodes = fetchurl {
url = "https://downloads.freenetproject.org/alpha/opennet/seednodes.fref";
sha256 = "08awwr8n80b4cdzzb3y8hf2fzkr1f2ly4nlq779d6pvi5jymqdvv";
};

freenet-jars = stdenv.mkDerivation {
pname = "freenet-jars";
inherit version;
patches = [
# gradle 7 support
(fetchpatch {
url = "https://github.com/freenet/fred/pull/827.patch";
sha256 = "sha256-T1zymxRTADVhhwp2TyB+BC/J4gZsT/CUuMrT4COlpTY=";
})
];

src = fetchurl {
url = "https://github.com/freenet/fred/releases/download/${version}/freenet.jar";
sha256 = "sha256-1Pjc8Ob4EN7N05QkGTMKBn7z3myTDaQ98N48nNSLstg=";
};

dontUnpack = true;
in stdenv.mkDerivation rec {
pname = "freenet";
inherit version patches;

installPhase = ''
mkdir -p $out/share/freenet
ln -s ${bcprov} $out/share/freenet/bcprov.jar
ln -s ${freenet_ext} $out/share/freenet/freenet-ext.jar
ln -s ${jna}/share/java/jna-platform.jar $out/share/freenet/jna_platform.jar
ln -s ${jna}/share/java/jna.jar $out/share/freenet/jna.jar
ln -s $src $out/share/freenet/freenet.jar
'';
src = fetchFromGitHub {
owner = "freenet";
repo = "fred";
rev = "refs/tags/build${version}";
hash = "sha256-pywNPekofF/QotNVF28McojqK7c1Zzucds5rWV0R7BQ=";
};

in stdenv.mkDerivation {
pname = "freenet";
inherit version;
postPatch = ''
rm gradle/verification-{keyring.keys,metadata.xml}
'';

src = substituteAll {
nativeBuildInputs = [ gradle jdk ];

wrapper = substituteAll {
src = ./freenetWrapper;
inherit bash coreutils jdk seednodes;
freenet = freenet-jars;
};

dontUnpack = true;
# https://github.com/freenet/fred/blob/next/build-offline.sh
# fake build to pre-download deps into fixed-output derivation
deps = stdenv.mkDerivation {
pname = "${pname}-deps";
inherit src version patches;

passthru.tests = { inherit (nixosTests) freenet; };
nativeBuildInputs = [ gradle perl ];
buildPhase = ''
export GRADLE_USER_HOME=$(mktemp -d)
gradle --no-daemon build
'';
# 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/$x/$3/$4/''${\($5 =~ s/okio-jvm/okio/r)}" #e' \
| sh
'';
# Don't move info to share/
forceShare = [ "dummy" ];
outputHashMode = "recursive";
# Downloaded jars differ by platform
outputHash = "sha256-CZf5M3lI7Lz9Pl8U/lNoQ6V6Jxbmkxau8L273XFFS2E=";
outputHashAlgo = "sha256";
};

# Point to our local deps repo
gradleInit = writeText "init.gradle" ''
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
clear()
maven { url '${deps}/'; metadataSources {mavenPom(); artifact()} }
}
}
repositories {
clear()
maven { url '${deps}/'; metadataSources {mavenPom(); artifact()} }
}
}
}
settingsEvaluated { settings ->
settings.pluginManagement {
repositories {
maven { url '${deps}/'; metadataSources {mavenPom(); artifact()} }
}
}
}
'';

buildPhase = ''
gradle jar -Dorg.gradle.java.home=${jdk} --offline --no-daemon --info --init-script $gradleInit
'';

installPhase = ''
runHook preInstall
install -Dm444 build/libs/freenet.jar $out/share/freenet/freenet.jar
ln -s ${freenet_ext} $out/share/freenet/freenet-ext.jar
mkdir -p $out/bin
install -Dm555 $src $out/bin/freenet
ln -s ${freenet-jars}/share $out/share
install -Dm555 ${wrapper} $out/bin/freenet
substituteInPlace $out/bin/freenet \
--subst-var-by outFreenet $out
ln -s ${deps} $out/deps
runHook postInstall
'';

passthru.tests = { inherit (nixosTests) freenet; };

meta = {
description = "Decentralised and censorship-resistant network";
homepage = "https://freenetproject.org/";
Expand Down
3 changes: 2 additions & 1 deletion pkgs/applications/networking/p2p/freenet/freenetWrapper
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! @bash@/bin/bash
set -eo pipefail
PATH=@coreutils@/bin:$PATH
export CLASSPATH=@freenet@/share/freenet/bcprov.jar:@freenet@/share/freenet/freenet-ext.jar:@freenet@/share/freenet/jna_platform.jar:@freenet@/share/freenet/jna.jar:@freenet@/share/freenet/freenet.jar
export CLASSPATH=$(find @outFreenet@/deps/ -name "*.jar"|grep -v bcprov-jdk15on-1.48.jar|tr $'\n' :)
CLASSPATH=$CLASSPATH:@outFreenet@/share/freenet/freenet-ext.jar:@outFreenet@/share/freenet/freenet.jar

export FREENET_HOME="$HOME/.local/share/freenet"
if [ -n "$XDG_DATA_HOME" ] ; then
Expand Down

0 comments on commit 96f6f7c

Please sign in to comment.