Since HCL2 is rendered at submit time, you can access the HCL variable values using the standard interpolation syntax—${var.domain} based on your example. This value will be materialized as a constant once you submit the job.
To put this into your context:
{{ $namesapce := env "NOMAD_NAMESPACE" -}}
{{ $domain := ${var.domain} -}}
{{ range $tag, $services := services | byTag -}}
{{ if eq $tag (print "caddy=" $namesapce) -}}{{ range $services -}}
# {{ .Name }} in {{ $namesapce }} -> {{.Name }}.{{ $domain }}
{{ .Name }}.{{ $domain }} {
import auth_snippet
import revproxy_snippet {{ .Name }}.service
}
{{ end }}{{ end }}{{ end }}
One note about this behavior. If your templates need to output ${...} tokens, you have to escape the $ by converting it to $$ or you will receive errors.