Recently I was packaging various pieces of code using the nix package manager https://nixos.org/nix/.
There is already a package for Isabelle. However, I had to modify this along the lines of: https://github.com/tomjridge/ocaml_btree/tree/master/.nix/isabelle.
There is an example package for lem here: https://github.com/tomjridge/ocaml_btree/tree/master/.nix/lem
The main problem I found is that it seems very difficult to get Isabelle to reuse heaps between packages. The eventual path I chose involves dropping into a nix-shell, and building the heaps in ~/.isabelle, rather than trying to reuse e.g. system heaps, or heaps from other packages. I assume that Isabelle somehow won't allow heap images to be reused across environments (perhaps there are hardcoded paths in heap images or something).
Anyway, to see how this all hangs together, try making the above ocaml_btree project following the README.md: https://github.com/tomjridge/ocaml_btree