Make missing library available after unvendoring package for derivation

I’m trying to make my first derivation (default.nix) for a binary package. It has vendored JRE8, so I unvendored it in the installPhase by symlinking to Nix’s JRE8. However, Nix’s JRE8 is missing one library ( Nix offers this library in a separate package (freetype). How can I make available this one missing library (please write the solution in code so I can understand)?

I saw makeWrapper and buildEnv, but I didn’t find examples for making missing libraries available.

You’re already making the library available through buildInputs - if you were compiling the software that would be enough :slight_smile:

Sadly it looks like the location of the shared object file is hard-coded somewhere in the binary. I’m a bit surprised by this, because I thought that the application would rely on java for finding things like that, so maybe your replacing is going wrong.

Some ways to solve that are described here, anyway: Packaging/Binaries - NixOS Wiki

Alternatively, it might be easier to execute any jars in that bundle directly, using Java’s classpath to make libraries available. I’m not sure how the package is bundled , but if you create a binary that just does:

${jre}/bin/java -cp <path/to/bundled/libraries/*.jar> -jar <path/to/main/jar>

and use it instead of the bundled one, this might work better.

Sorry for the lack of code for this approach, but it’d take some experimenting to get right.

1 Like

Thanks for your reply! I added autoPatchelfHook to nativeBuildInputs, and now am able to get the program running. Still, the program throws many errors while running it. For example,

The 'JavaDesigner' repository index is missing.

which I suppose to be related to the bundled JAR usr/lib/modelio-open-source4.1/bundle/java/javadesigner.jar. In the installPhase, I’ve tried wrapping the executable with the classpath,

makeWrapper ${jre8}/bin/java $out/usr/lib/modelio-open-source4.1/modelio --add-flags "-classpath $out/usr/lib/modelio-openf-source4.1/bundle/java/javadesigner.jar"

but when I try to run the executable, I just get

$ ./result/bin/modelio
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32	  use a 32-bit data model if available
    -d64	  use a 64-bit data model if available
    -server	  to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
                  set a system property
                  enable verbose output
    -version      print product version and exit
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
                  enable assertions with specified granularity
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
                  load native agent library by full pathname
                  load Java programming language agent, see java.lang.instrument
                  show splash screen with specified image

It seems I need to add a package after the jar in the classpath? But I’m at a loss how to know which one to add? Do you have any idea?

No, sorry, I’ve never used modelio! If you can find their source code, whatever packaging mechanism they use will probably contain something like io.model.ModelIO. That’s what you’ll need to use.