diff --git a/nixos/modules/services/networking/i2p.nix b/nixos/modules/services/networking/i2p.nix index c5c7a955cbd4..5c6c08831a43 100644 --- a/nixos/modules/services/networking/i2p.nix +++ b/nixos/modules/services/networking/i2p.nix @@ -5,7 +5,8 @@ with lib; let cfg = config.services.i2p; homeDir = "/var/lib/i2p"; -in { +in +{ ###### interface options.services.i2p.enable = mkEnableOption (lib.mdDoc "I2P router"); @@ -27,7 +28,7 @@ in { User = "i2p"; WorkingDirectory = homeDir; Restart = "on-abort"; - ExecStart = "${pkgs.i2p}/bin/i2prouter-plain"; + ExecStart = "${pkgs.i2p}/bin/i2prouter"; }; }; }; diff --git a/pkgs/tools/networking/i2p/default.nix b/pkgs/tools/networking/i2p/default.nix index 6958a12cdf3d..5ab401af7fac 100644 --- a/pkgs/tools/networking/i2p/default.nix +++ b/pkgs/tools/networking/i2p/default.nix @@ -1,60 +1,96 @@ { lib , stdenv -, ps -, coreutils -, fetchurl +, fetchzip , jdk -, jre , ant , gettext , which +, dbip-country-lite , java-service-wrapper +, makeWrapper +, gmp }: stdenv.mkDerivation (finalAttrs: { pname = "i2p"; version = "2.4.0"; - src = fetchurl { - urls = map (mirror: "${mirror}/${finalAttrs.version}/i2psource_${finalAttrs.version}.tar.bz2") [ - "https://download.i2p2.de/releases" - "https://files.i2p-projekt.de" - "https://download.i2p2.no/releases" + src = fetchzip { + urls = map (mirror: "${mirror}${finalAttrs.version}/i2psource_${finalAttrs.version}.tar.bz2") [ + "https://github.com/i2p/i2p.i2p/releases/download/i2p-" + "https://download.i2p2.de/releases/" + "https://files.i2p-projekt.de/" + "https://download.i2p2.no/releases/" ]; - sha256 = "sha256-MO+K/K0P/6/ZTTCsMH+GtaazGOLB9EoCMAWEGh/NB3w="; + hash = "sha256-RESN1qA/SD9MajUSJyXssNZnph2XZge7xr2kTgOp5V4="; }; - buildInputs = [ jdk ant gettext which ]; - patches = [ ./i2p.patch ]; + strictDeps = true; + + nativeBuildInputs = [ + makeWrapper + ant + gettext + jdk + which + ]; + + buildInputs = [ gmp ]; + + postConfigure = '' + rm -r installer/lib + mkdir -p installer/lib/wrapper/all/ + # The java-service-wrapper is needed for build but not really used in runtime + ln -s ${java-service-wrapper}/lib/wrapper.jar installer/lib/wrapper/all/wrapper.jar + # Don't use the bundled geoip data + echo "with-geoip-database=true" >> override.properties + ''; buildPhase = '' + # When this variable exists we can build the .so files only. + export DEBIANVERSION=1 + pushd core/c/jcpuid + ./build.sh + popd + pushd core/c/jbigi + ./build_jbigi.sh dynamic + popd export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" - ant preppkg-linux-only + SOURCE_DATE_EPOCH=0 ant preppkg-unix ''; installPhase = '' - set -B - mkdir -p $out/{bin,share} - cp -r pkg-temp/* $out - - cp ${java-service-wrapper}/bin/wrapper $out/i2psvc - cp ${java-service-wrapper}/lib/wrapper.jar $out/lib - cp ${java-service-wrapper}/lib/libwrapper.so $out/lib - - sed -i $out/i2prouter -i $out/runplain.sh \ - -e "s#uname#${coreutils}/bin/uname#" \ - -e "s#which#${which}/bin/which#" \ - -e "s#%gettext%#${gettext}/bin/gettext#" \ - -e "s#/usr/ucb/ps#${ps}/bin/ps#" \ - -e "s#/usr/bin/tr#${coreutils}/bin/tr#" \ - -e "s#%INSTALL_PATH#$out#" \ - -e 's#%USER_HOME#$HOME#' \ - -e "s#%SYSTEM_java_io_tmpdir#/tmp#" \ - -e "s#%JAVA%#${jre}/bin/java#" - mv $out/runplain.sh $out/bin/i2prouter-plain + mkdir -p $out/{bin,share,geoip} + mv pkg-temp/* $out + mv core/c/jbigi/*.so $out/lib mv $out/man $out/share/ - chmod +x $out/bin/* $out/i2psvc rm $out/{osid,postinstall.sh,INSTALL-headless.txt} + + for jar in $out/lib/*.jar; do + if [ ! -z $CP ]; then + CP=$CP:$jar; + else + CP=$jar + fi + done + + makeWrapper ${jdk}/bin/java $out/bin/i2prouter \ + --add-flags "-cp $CP -Djava.library.path=$out/lib/ -Di2p.dir.base=$out -DloggerFilenameOverride=logs/log-router-@.txt" \ + --add-flags "net.i2p.router.RouterLaunch" + + ln -s ${dbip-country-lite.mmdb} $out/geoip/GeoLite2-Country.mmdb + ''; + + doInstallCheck = true; + + installCheckPhase = '' + runHook preInstallCheck + + # Check if jbigi is used + java -cp $out/lib/i2p.jar -Djava.library.path=$out/lib/ net.i2p.util.NativeBigInteger \ + | tee /dev/stderr | grep -Fw "Found native library" || exit 1 + + runHook postInstallCheck ''; meta = with lib; { diff --git a/pkgs/tools/networking/i2p/i2p.patch b/pkgs/tools/networking/i2p/i2p.patch deleted file mode 100644 index 3bb4da729173..000000000000 --- a/pkgs/tools/networking/i2p/i2p.patch +++ /dev/null @@ -1,43 +0,0 @@ -diff --git a/installer/resources/i2prouter b/installer/resources/i2prouter -index 365737d89..2ea14db3e 100644 ---- a/installer/resources/i2prouter -+++ b/installer/resources/i2prouter -@@ -49,7 +49,7 @@ APP_LONG_NAME="I2P Service" - - # gettext - we look for it in the path - # fallback to echo is below, we can't set it to echo here. --GETTEXT=$(which gettext > /dev/null 2>&1) -+GETTEXT=%gettext% - - # Where to install the systemd service - SYSTEMD_SERVICE="/etc/systemd/system/${APP_NAME}.service" -diff --git a/installer/resources/runplain.sh b/installer/resources/runplain.sh -index eb4995dfe..0186cede3 100644 ---- a/installer/resources/runplain.sh -+++ b/installer/resources/runplain.sh -@@ -25,7 +25,7 @@ CP= - - # Try using the Java binary that I2P was installed with. - # If it's not found, try looking in the system PATH. --JAVA=$(which "%JAVA_HOME"/bin/java || which java) -+JAVA=%JAVA% - - if [ -z $JAVA ] || [ ! -x $JAVA ]; then - echo "Error: Cannot find java." >&2 -@@ -44,15 +44,4 @@ if [ $(uname -s) = "Darwin" ]; then - export JAVA_TOOL_OPTIONS="-Djava.awt.headless=true" - fi - JAVAOPTS="${MAXMEMOPT} -Djava.net.preferIPv4Stack=${PREFERv4} -Djava.library.path=${I2P}:${I2P}/lib -Di2p.dir.base=${I2P} -DloggerFilenameOverride=logs/log-router-@.txt" --( -- nohup ${JAVA} -cp \"${CP}\" ${JAVAOPTS} net.i2p.router.RouterLaunch > /dev/null 2>&1 --) & --PID=$! -- --if [ ! -z $PID ] && kill -0 $PID > /dev/null 2>&1 ; then -- echo "I2P started [$PID]" >&2 -- echo $PID > "${I2PTEMP}/router.pid" --else -- echo "I2P failed to start." >&2 -- exit 1 --fi -+exec ${JAVA} -cp \"${CP}\" ${JAVAOPTS} net.i2p.router.RouterLaunch