Hi.
In case it helps, debhelper has already a provision for these kind of things:
HOME, XDG_*
In compat 13 and later, these environment variables are reset before
invoking the
upstream build system via the dh_auto_* helpers. The variables HOME
(all dh_auto_*
helpers) and XDG_RUNTIME_DIR (dh_auto_test only) will be set to a
writable directory.
All remaining variables and XDG_RUNTIME_DIR (except for during
dh_auto_test) will be
cleared.
The HOME directory will be created as an empty directory but it will
be reused between
calls to dh_auto_*. Any content will persist until explicitly
deleted or dh_clean.
So, maybe by using this feature it would be possible to simplify whatever
solution you
had in mind.
(One of the times where a new imagemagick broke a bunch of packages, I remember
that this
feature, for packages already using compat 13, made the fix to be a lot simpler
and nicer).
Thanks.