String
Single-line string
nix
"single"
1
Multi-line string
When single-line string exceeds column number you want, use multi-line string. Leading two spaces are trimmed
nix
''
this is a
linebreak!
''
1
2
3
4
2
3
4
is equivalent to
nix
"this is a \nlinebreak!"
1
Multi-line string is typically useful to write shell scripts inside nix
.
nix
stdenv.mkDerivation {
postInstall =
''
mkdir $out/bin $out/etc
cp foo $out/bin
echo "Hello World" > $out/etc/foo.conf
${if enableBar then "cp bar $out/bin" else ""}
'';
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Escaping
To escape in multi-line, prefix with ''
nix
''
This is a dollar sign:
''$
This is a new line ''\n
This is a single quote: ''\'
This is also a single quote: '''
''
1
2
3
4
5
6
7
2
3
4
5
6
7
String concatenation
nix
"foo" + "bar"
1
String interpolation
nix
"git path managed by nix: ${pkgs.git}"
1