How do I generate a YAML list in a nix module?
There is a toYAML function in nixpkgs (pkgs.lib.generators.toYAML) but it’s the same as the toJSON function which works since YAML is a superset of JSON.
If you feel like you want human-readable YAML, you can pass the output of toJSON to remarshal’s json2yaml. This is what we’re doing in the Home Assistant module.
2 Likes
I didn’t know json wasn’t human-readable.
It depends what version of YAML you need. You may use a piece of simple code like this one (feel free to use under the nixpkgs license; EDIT: newer version here). That was to generate it directly. It may be fine for your case to use a build-time convertor, as suggested above, or some other way.