I clearly understand, that this text has to be correctly escaped because "ref" and operator => are being treated as two variables comparison operation.
Please suggest, how to escape all possible special characters and treat all data as regular text that means nothing.
Escaping rules are described in the Nix manual. For '' strings:
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 $ . Linefeed, carriage-return and tab characters can be written as ''\n , ''\r , ''\t , and ''\ escapes any other character.
You should replace ${ref} with ''${ref} in your example, so that it does not try to interpolate a Nix variable ref. The sequence => is not special. Unfortunately the escaping rules are different from double-quote " strings, where \ is used to escape ${ instead.
As long as it resolves to a string on eval you can put any expression in parens, and you can import external text files like so:
[
(builtins.readFile ./config.exs)
# or using interpolation to blend strings with code
''
some import string content
${lib.fileContents ./other.txt}
''
]
builtins.readFile adds an extra newline at the end of the file, if you need to avoid this you can use lib.fileContents from nixpkgs instead.