Testing Haskell projects that use homeless shelter up

If you try to enable Haskell tests that use (I think) temporary files you’ll get an error like:

$ nix-build
error: creating directory ‘/homeless-shelter’: Permission denied

One workaround suggests using a nix directory in home.

Another solution I can’t find recommends using functions from impure.nix to allow this.

I also considered using nix-shell --run "cabal test" after nix build but it might fail too.

I would prefer nix build run my stateful tests and fail. How do others do this?

Is there a way to both use tests like this and preserve purity at the nix level? Or is there no hope for tests that have to write to the homeless shelter?

I see one workaround suggested by Peti is setting HOME to somewhere writable.