Timothy R. Butler's answer is great, but in 2021, lots of things have changed. It's a lot simpler to get working now, I think. Here's what I did with TrueNAS 12.0-U1.1 (I picked 12.2-RELEASE for the jail):
# setup a jail which gets its own IP - I did IPv4 only
pkg install avahi cups python3 py37-pycups ncurses vim
drivers. you will have to play with ones to find one that works for you. you can try gutenprint:
pkg install gutenprint
or you can try hplip:
pkg install hplip
or you can try foomatic - grab a PPD from openprinting.org. this was the only thing
that worked reliably for me and enabled all supported resolutions without
advertising it as a duplex color printer, because it uses the ghostscript pxlmono
driver for my LaserJet 2100... maybe hplip would be great if it actually knew what
my printer supported properly
enable services
echo "avahi_daemon_enable=YES" >> /etc/rc.conf
echo "cupsd_enable=YES" >> /etc/rc.conf
echo "dbus_enable=YES" >> /etc/rc.conf
create an admin account, invite to group "wheel", fill in full name and username, leave rest at defaults
adduser
Listen on 0.0.0.0:631 instead of 127.0.0.1
Allow All on /, /admin, /admin/conf, and /admin/log
Require user @SYSTEM on /admin
AuthType Default on /admin
vim /usr/local/etc/cups/cupsd.conf
stop making avahi advertise SSH/SFTP
rm /usr/local/etc/avahi/services/sftp-ssh.service /usr/local/etc/avahi/services/ssh.service
start services
/usr/local/etc/rc.d/dbus restart
/usr/local/etc/rc.d/avahi-daemon restart
/usr/local/etc/rc.d/cupsd restart
visit http://jail:631 and setup printer, share it, configure, set as server default, print test page to check proper driver
with latest CUPS, you do NOT need to add any mime conversions! but because apple,
you have to publish the right stuff to ZeroConf. this script does this:
fetch -o /usr/local/bin/airprint-generate.py https://raw.githubusercontent.com/tjfontaine/airprint-generate/master/airprint-generate.py
chmod +x /usr/local/bin/airprint-generate.py
cd /usr/local/etc/avahi/services
You may want to edit the script to add feature flags, see https://wiki.debian.org/CUPSAirPrint for more details.
You may also want to add application/vnd.cups-pdf to the DOCUMENT_TYPES set to True
/usr/local/bin/airprint-generate.py
Avahi will pick up the service immediately and begin publishing it. Edit the file that the script outputted if you want to change how stuff rendered or the features announced or whatever. Debian's docs say you have to have something in the URF record other than "none", but this works for me on iOS 12. You can fill in the URF record from the Debian wiki example if you want.