Change:
<del> { stdenv, cmake, pkgconfig, libpng, libtiff, lcms2, glib/*passthru only*/ , sharedLibsSupport ? true # Build shared libraries , codecSupport ? true # Codec executables </del> <ins> { stdenv, fetchurl, cmake, pkgconfig , libpng, libtiff, lcms2 </ins> , mj2Support ? true # MJ2 executables , jpwlLibSupport ? true # JPWL library & executables <del> , jpipLibSupport ? true # JPIP library & executables </del> <ins> , jpipLibSupport ? false # JPIP library & executables </ins> , jpipServerSupport ? false, curl ? null, fcgi ? null # JPIP Server #, opjViewerSupport ? false, wxGTK ? null # OPJViewer executable <del> , openjpegJarSupport ? false, jdk ? null # Openjpeg jar (Java) </del> <ins> , openjpegJarSupport ? false # Openjpeg jar (Java) </ins> , jp3dSupport ? true # # JP3D comp , thirdPartySupport ? false # Third party libraries - OFF: only build when found, ON: always build , testsSupport ? false <ins> , jdk ? null </ins> # Inherit generics <del> , branch, src, version, ... </del> <ins> , branch, sha256, version, ... </ins> }: <del> assert jpipServerSupport -> (jpipLibSupport && (curl != null) && (fcgi != null)); </del> <ins> assert jpipServerSupport -> jpipLibSupport && curl != null && fcgi != null; </ins> #assert opjViewerSupport -> (wxGTK != null); <del> assert openjpegJarSupport -> (jdk != null); assert testsSupport -> codecSupport; </del> <ins> assert (openjpegJarSupport || jpipLibSupport) -> jdk != null; </ins> let <del> mkFlag = optSet: flag: if optSet then "-D${flag}=ON" else "-D${flag}=OFF"; </del> <ins> inherit (stdenv.lib) optional optionals; mkFlag = optSet: flag: "-D${flag}=${if optSet then "ON" else "OFF"}"; </ins> in <del> with stdenv.lib; </del> stdenv.mkDerivation rec { name = "openjpeg-${version}"; <del> inherit branch; inherit version; inherit src; </del> <ins> src = fetchurl { url = "mirror://sourceforge/openjpeg.mirror/${version}/openjpeg-${version}.tar.gz"; inherit sha256; }; </ins> cmakeFlags = [ <del> (mkFlag sharedLibsSupport "BUILD_SHARED_LIBS") (mkFlag codecSupport "BUILD_CODEC") </del> <ins> "-DCMAKE_INSTALL_NAME_DIR=${CMAKE_INSTALL_PREFIX}/lib" "-DBUILD_SHARED_LIBS=ON" "-DBUILD_CODEC=ON" </ins> (mkFlag mj2Support "BUILD_MJ2") (mkFlag jpwlLibSupport "BUILD_JPWL") (mkFlag jpipLibSupport "BUILD_JPIP") (mkFlag jpipServerSupport "BUILD_JPIP_SERVER") #(mkFlag opjViewerSupport "BUILD_VIEWER") <ins> "-DBUILD_VIEWER=OFF" </ins> (mkFlag openjpegJarSupport "BUILD_JAVA") (mkFlag jp3dSupport "BUILD_JP3D") (mkFlag thirdPartySupport "BUILD_THIRDPARTY") (mkFlag testsSupport "BUILD_TESTING") <del> ] ++ stdenv.lib.optionals stdenv.isDarwin [ "-DCMAKE_INSTALL_NAME_DIR=${CMAKE_INSTALL_PREFIX}/lib" </del> ]; <del> nativebuildInputs = [ pkgconfig ]; </del> <ins> nativeBuildInputs = [ cmake pkgconfig ]; </ins> <del> buildInputs = [ cmake ] </del> <ins> buildInputs = [ ] </ins> ++ optionals jpipServerSupport [ curl fcgi ] #++ optional opjViewerSupport wxGTK <del> ++ optional openjpegJarSupport jdk; </del> <ins> ++ optional (openjpegJarSupport || jpipLibSupport) jdk; </ins> propagatedBuildInputs = [ libpng libtiff lcms2 ]; <del> postInstall = glib.flattenInclude + '' mkdir -p "$out/lib/pkgconfig" cat > "$out/lib/pkgconfig/libopenjp2.pc" <<EOF prefix=$out libdir=$out/lib includedir=$out/include Name: openjp2 Description: JPEG2000 library (Part 1 and 2) URL: http://www.openjpeg.org/ Version: ${version} Libs: -L$out/lib -lopenjp2 Cflags: -I$out/include EOF ''; </del> passthru = { incDir = "openjpeg-${branch}"; }; <del> meta = { </del> <ins> meta = with stdenv.lib; { </ins> description = "Open-source JPEG 2000 codec written in C language"; <del> homepage    = http://www.openjpeg.org/; license     = licenses.bsd2; maintainer  = with maintainers; [ codyopel ]; platforms   = platforms.all; </del> <ins> homepage = http://www.openjpeg.org/; license = licenses.bsd2; maintainer = with maintainers; [ codyopel ]; platforms = platforms.all; </ins> }; }

Discussion:
I tried building openjpeg as a dependency when using on Mac OS X, and it failed on trying to run javac. Nevertheless, its derivation seemed to define (long line follows). The package built successfully after I installed an external JDK. It seems that for some strange reason the build script is ignoring the option.
Should fix this. JPIP builds a java component, but the cmake script does not require for
Thanks for the quick reaction! I will try the fix soon!