Generating YAML in a nix module

#1

How do I generate a YAML list in a nix module?

0 Likes

#2

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.

0 Likes

#3

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.

0 Likes

#4

I didn’t know json wasn’t human-readable.

0 Likes

#5

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). 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.

0 Likes