What to do about ~/.slime and ~/.cache?

Hi folks,

New nix user here, looking for some advice on how to package something.

The context is that I have a derivation for my own fork of Next browser, in
which I have applied some fixes/modifications to the qtwebengine frontend to
make it usable. I use macOS at home though, and unfortunately a lot of the
nixpkgs derivations for the Next dependencies don’t support Darwin. One of these
is ASDF, which means that common-lisp effectively useless on Darwin.

To get around this, instead of using the nix derivations for lisp packages, I
just let Next install these from quicklisp directly. However, the build process
wants to create some directories in $HOME, which I can get around as follows:

buildPhase = ''
  export HOME=$(pwd)
  make app-bundle

The resulting app bundle for Next works fine, except for Swank (I am unable to
connect to Swank server from emacs). From what I can tell, the problem is that
the build tries to create a set of of dot-dirs in $HOME: ~/.cache, and
~/.slime, at least one of which is needed for Slime/Swank to function properly
(and for some reason, dumping these into the build dir is insufficient; I have
also tried moving them to the output .app bundle, and that is also
insufficient). I can fix this completely (meaning that I CAN connect to the
Swank server) by instead using the following as my buildPhase:

buildPhase = if stdenv.isDarwin then ''
  export HOME=$out
  make app-bundle

but then I end up with symlinks for ~/.cache and ~/.slime in ~/.nix-profile
(this is all using home_manager). I anticipate this eventually being a problem
if I ever encounter another package that either wants to create a .cache dir, or
needs to use Swank, since this will lead to a collision.

I am looking through the sources for quicklisp-to-nix to try to figure out how
this is dealt with in the nixpkgs derivation for Swank, but I think my nix-ese
might be too cursory to really understand what’s going on there. Wondering if
anybody else has any advice on how to deal with this.


EDIT: So it dawned on my simple mind that moving the directories after the fact
probably doesn’t work, because the packages are probably still expecting them to
exist in $HOME. I changed my build and install phases to:

buildPhase = ''
  export HOME=$out/Applications/Next.app/Contents/MacOS/
  make app-bundle

installPhase = ''
  mkdir -p $out/Applications
  mkdir -p $out/bin
  cp -rv ./Next.app $out/Applications/
  ln -s $out/Applications/Next.app/Contents/MacOS/next $out/bin/next

And now everything seems to work OK. This still feels like a weird solution
though (there must be some idiomatic nix way of stashing build outputs to $HOME that are
necessary for the program to function properly, and hence cannot just get dumped
to homeless-shelter).