I want to create a Nix package for a Java library that would be more or less appropriate for further inclusion to nixpkgs. However, I can’t find any definite example to follow.
The library in question is HikariCP, a JDBC connection pool. Its only runtime dependency is slf4j-api.
Now, JDBC pools are somewhat special with regards to how they can be used. Among other cases, they can be dynamically added to classpath of application containers (such as Tomcat) to make them available to all applications; so they are not just buried and forgotten within Java applications, they may need to be visible to the system administrator.
I want to support (at least) the following ways of using the package:
- Add the necessary JAR paths to
services.tomcat.commonLibs
; - Copy the necessary JARs to the web application’s directory during deployment.
It’s similar to the situation with JDBC drivers: they also may need to be put into application container’s classpath. So I looked at existing JDBC driver packages (postgresql_jdbc
, mssql_jdbc
), and they are quite simple: they just fetch JARs from github/maven and put them into share/java
. The difference is that they don’t have dependencies, and here is where the interesting/difficult part begins.
So, I created packages for HikariCP and slf4j-api, which contain the respective JARs. However, how do I connect them? I want to be able to “forget” that the former depends on the latter, only reference HikariCP in my NixOS configuration, and have its dependencies added automatically, in a way similar to this contrived example:
services.tomcat.commonLibs =
myPkgs.hikaricp_3_4_5.jars
++ [
# Other JARs I may need
];
Is there a standard/ideomatic way of achieving this?