I have 2 NixOs installations, a server and a desktop,
I build some custom packages and a service for a java application.
It works fine, when I test it on the desktop, but when I move it to
the server it don’t work anymore.
The current main problem is that /run/current-system/sw/share/java don’t
exist on the server, but it does get build and merged correctly on the desktop.
The desktop’s system.stateVersion = “22.11” and
the server’s system.stateVersion = “23.05”
I also add some scripts in bin/
[nix-shell:/etc/nixos]# tree /nix/store/01d4f7qns94mg1sfh9f45zxs4ksw121x-corenlp-4.5.7/bin/
/nix/store/01d4f7qns94mg1sfh9f45zxs4ksw121x-corenlp-4.5.7/bin/
├── corenlp
└── corenlp-server
and they get merged correctly into
# which corenlp
/run/current-system/sw/bin/corenlp
# ls -ltr /run/current-system/sw/bin/corenlp
lrwxrwxrwx 1 root root 69 Jan 1 1970 /run/current-system/sw/bin/corenlp -> /nix/store/01d4f7qns94mg1sfh9f45zxs4ksw121x-corenlp-4.5.7/bin/corenlp
But /share/java don’t appear on the server, but they do exist in the package.
You typically don’t want your package to use binary libraries from some global path. This is why the set of paths that get linked globally is rather restricted by default.
It’s better to encode exact paths in the package’s derivation from which it should take the dependencies or make the path relative to the package’s output path instead. This makes the package work hermetically; without any implicit dependencies such as /run/current-system/sw/share/java/.
Then I have “databases” lets call them A B C D E F. etc.
A user will typical only install a few of the databases, since they are big.
But the main program, need to be able to find them. Since it is java, we
need to be able to construct a CLASSPATH with the databases, they are jar files.
When I install the main program, I can not know if some database is also installed.
But if installed in the same directory, then a CLASSPATH can be built at runtime.
If you know of another way of solving this problem, please let my know.
I assume these “databases” are java libraries (jars) that the program loads at runtime?
If you need the runtime inputs to be optional and they do not need to be present in order to build the program itself, I’d employ a wrapper pattern. This would be another nix package that takes the runtime libs as an override input and simply calls makeWrapper on the java -jar command with the actual derivation’s main jar and it sets the CLASSPATH accordingly as @waffle8946 mentioned.