No no, all in one string.
Nix files are very consistently structured—you’re building an expression out of building blocks:
- atomic literals like strings, numbers, booleans, and paths
- list and attrset literals
- function expressions, also called lambdas
- operators and function calls
- fancier expressions like
let,with, andassert
In particular, a Nix configuration is one big attrset. An attrset literal can only contain two types of things:
some.attribute.path = expression;- an
inheritclause
That’s it! Nix the language will complain if you try to stick bare string literals inside an attrset, like { "example"; }, because the language has no rules for what that would mean.
(Nix language basics is a more complete introduction to these concepts.)
So if you’re setting an option (like sound.extraConfig, but this goes for any option), you have to set it to a single expression. Now some options will accept a complex expression, like a list. It’s not unimaginable that sound.extraConfig, in an alternate universe, might accept the following:
sound.extraConfig = [
"defaults.pcm.!card 3"
"defaults.pcm.!card 4"
"defaults.pcm.!card 5"
];
(Note the square brackets: they mean that this is a list, not an attrset, so it’s okay to have bare strings here! Also note that the only difference between "this kind of string" and
''
this kind of string
''
is how whitespace is handled; the latter is typically used when a string has line breaks because it takes care of stripping out common indentation.)
That’s a valid expression, as far as Nix the language is concerned, but it won’t work because the type of sound.extraConfig, as you can see in the Type entry when looking at sound.extraConfig on NixOS Search, is strings concatenated with "\n" (a multi-line string, in other words) and not list of string. So that example would be a problem for the NixOS module system, and you’d get an error if you tried it.
No, what the NixOS module system wants is a single string. One could build that string in complex ways, but if you have a big block of non-Nix configuration that you just want to stuff in there, all you need to do is make a single multi-line string literal out of it.