The idea here is that if FOO is defined, $%FOO% will be replaced with the contents of the FOO variable, and searchreplace will (probably) make no changes to that.
!searchreplace ENVTEMP '$%FOO%' '%FOO%' ''
!if '${ENVTMP}' == '$'
!echo "FOO is not set"
!endif
If it's not set, environment variable substitution will not happen, and searchreplace will leave only the dollar sign.
I was hoping to do something a bit more straightforward, like this:
but it looks like NSIS is doing environment substitution even though I tried to "escape" the dollar sign in the !if statement.
!define ENVTMP '$%FOO%'
# This doesn't work
!if '${ENVTMP}' == '$$%FOO%'
!echo "FOO is not set"
!endif