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.
I want to note that the link to this content has changed, and it’s no longer in the nixpkgs manual, which confused me quite a lot when looking for it. You can find the relevant content here as of 2.24.