Defining Unitful Units Programmatically

I am processing some datasets involving altitude measurements that mixes MSL and AGL altitude units. I would like to define custom units to minimize opportunity for error. In my case, the reference offset altitude will be read from a file.

I would like to do something like:

using Unitful

@unit ft_MSL "ft_MSL" FtMSL 1*u"ft" false
function make_AGL_unit(f)
   msl_alt = alt_from_file(f) * u"ft_MSL"
   @affineunit ft_AGL "ft_AGL" $(altitude(dz))

However, interpolation doesn’t work, producing LoadError: syntax: "$" expression outside quote.