John Mercier

[A software developer interested in java, groovy, and nixos]

After a bot upgraded jbake I was unable to run it on my system. The cause was due to a change in the jbakes script detected the java executable. With some help from the nix community I was able to fix it.


Starting jbake would output an error.

0 + john@n1 nixpkgs $ ./result/bin/jbake

ERROR: JAVA_HOME is set to an invalid directory: /nix/store/szwdr2qmldwn0q227qfrjpagzzzvxsb0-openjdk-9.0.4-b11/lib/openjdk

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.


The new script which runs jbake switched from using the java command available on $PATH to calling java from $JAVA_HOME/bin/java. The nix package substituted the java command with a full path to the executable.

substituteInPlace bin/jbake --replace "java" "${jre}/bin/java"


This is fixed by removing the call to substituteInPlace and adding wrapProgram.

     installPhase = ''
 -    substituteInPlace bin/jbake --replace "java" "${jre}/bin/java"
      mkdir -p $out
      cp -vr * $out
 +    wrapProgram $out/bin/jbake --set JAVA_HOME "${jre}"

wrapProgram adds the correct JAVA_HOME environment variable.

preventing future issues

The best thing to do is write a test for jbake.

Information on writing tests is found here.

NixOS provides a powerful testing framework. Each test is isolated in a virtual machine (or many vms) built with the exact specification in the test. Once the vm is running a perl test script is run. If the test script fails the test fails.

2014 - 2018 | Mixed with Foundation v5.5.1 | Baked with JBake v2.6.1