2
votes

I am trying to build a Freeplane derivation based on Freemind, see: https://github.com/razvan-panda/nixpkgs/blob/freeplane/pkgs/applications/misc/freeplane/default.nix

{ stdenv, fetchurl, jdk, jre, gradle }:

stdenv.mkDerivation rec {
  name = "freeplane-${version}";
  version = "1.6.13";

  src = fetchurl {
    url = "mirror://sourceforge/project/freeplane/freeplane%20stable/freeplane_src-${version}.tar.gz";
    sha256 = "0aabn6lqh2fdgdnfjg3j1rjq0bn4d1947l6ar2fycpj3jy9g3ccp";
  };

  buildInputs = [ jdk gradle ];

  buildPhase = "gradle dist";

  installPhase = ''
    mkdir -p $out/{bin,nix-support}
    cp -r ../bin/dist $out/nix-support
    sed -i 's/which/type -p/' $out/nix-support/dist/freeplane.sh

    cat >$out/bin/freeplane <<EOF
    #! /bin/sh
    JAVA_HOME=${jre} $out/nix-support/dist/freeplane.sh
    EOF
    chmod +x $out/{bin/freeplane,nix-support/dist/freeplane.sh}
  '';

  meta = with stdenv.lib; {
    description = "Mind-mapping software";
    homepage = https://www.freeplane.org/wiki/index.php/Home;
    license = licenses.gpl2Plus;
    platforms = platforms.linux;
  };
}

During the gradle build step it is throwing the following error:

building path(s) ‘/nix/store/9dc1x2aya5p8xj4lq9jl0xjnf08n7g6l-freeplane-1.6.13’ unpacking sources unpacking source archive /nix/store/c0j5hgpfs0agh3xdnpx4qjy82aqkiidv-freeplane_src-1.6.13.tar.gz source root is freeplane-1.6.13 setting SOURCE_DATE_EPOCH to timestamp 1517769626 of file freeplane-1.6.13/gitinfo.txt patching sources configuring no configure script, doing nothing building

FAILURE: Build failed with an exception.

  • What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. builder for ‘/nix/store/id4vfk3r6fd4zpyb15dq9xfghf342qaa-freeplane-1.6.13.drv’ failed with exit code 1 error: build of ‘/nix/store/id4vfk3r6fd4zpyb15dq9xfghf342qaa-freeplane-1.6.13.drv’ failed

Running gradle dist from terminal works fine. I'm guessing that maybe one of the globally installed Nix packages provides a fix to the issue and they are not visible during the build.

I searched a lot but couldn't find any working solution. For example, removing the ~/.gradle folders didn't help.

Update

To reproduce the issue just git clone https://github.com/razvan-panda/nixpkgs, checkout the freeplane branch and run nix-build -A freeplane in the root of the repository.

Link to GitHub issue

1
This seems to be a problem with how gradle has been packaged and/or patched. Minimal example: NIX_PATH=nixpkgs=$HOME/nixpkgs nix-build --expr 'with import <nixpkgs> {}; stdenv.mkDerivation { src = ./empty-directory; name = "foo"; buildInputs = [gradle]; buildPhase = "gradle --stacktrace"; } 'Robert Hensing
@RobertHensing I don't understand why gradle dist works just fine when run from terminal then. Should I create an Issue about this on Nixpkgs repository?Răzvan Flavius Panda
It even works in a 'pure' nix-shell (s/nix-build/nix-shell --pure) which is not as clean as the nix-build sandbox. For example $HOME is available in nix-shell --pure, but that doesn't seem to be the problem in this case, so I don't know what is missing. This ought to work, so reporting the issue is appropriate.Robert Hensing

1 Answers

0
votes

To fix this error: What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64. do the following:

  1. Check if your Gradle cache (**~user/.gradle/**native folder exist at all or not).
  2. Check if your Gradle cache (~user/.gradle/native folder exist and the file in question i.e. libnative-platform.so exists in that directory or not).
  3. Check if the above folder ~user/.gradle or ~/.gradle/native or file: ~/.gradle/native/libnative-platform.so has valid permissions (should not be read-only. Running chmod -R 755 ~/.gradle is enough).

IF you don't see native folder at all or if your native folder seems corrupted, run your Gradle task ex: gradle clean build using -g or --gradle-user-home option and pass it's value.

Ex: If I ran mkdir /tmp/newG_H_Folder; gradle clean build -g /tmp/newG_H_Folder, you'll see Gradle will populate all the required folder/files (that it needs to run even before running any task or any option) are now in this new Gradle Home folder (i.e. /tmp/newG_H_Folder/.gradle directory).

From this folder, you can copy - just the native folder to your user's ~/.gradle folder (take backup of existing native folder in ~/.gradle first if you want to) if it already exists -or copy the whole .gradle folder to your ~ (home directory).

Then rerun your Gradle task and it won't error out anymore.

Gradle docs says: https://docs.gradle.org/current/userguide/command_line_interface.html -g, --gradle-user-home Specifies the Gradle user home directory. The default is the .gradle directory in the user’s home directory.