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 (libfreetype.so.6). 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.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  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
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  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.