Since ${ and '' have special meaning in indented strings, you need a way to quote them. $ can be escaped by prefixing it with '' (that is, two single quotes), i.e., ''$ . '' can be escaped by prefixing it with ' , i.e., ''' . $ removes any special meaning from the following $ .
I had an issue with a bash function as a string literal in Nix. Nix wanted to do the substitution when building when substitution was only meant for running the bash script. Using this tip Nix ignored them allowing me to build.