I found a lot of posts about converting from/to JSON, YAML, TOML, etc…
This comes up a lot. For example, consider alacritty’s colorscheme configuration.
It has a colors entry that matches the yaml config 1:1.
It would be nice if we can have config.colors = fromYaml ./colors.yaml inside alacritty.nix.
Currently I have to copy the yaml file, then manually change it to nix syntax when I want to experiment with stuff like this.
I looked at
Starship Nix code and I saw that it is using pkgs.formats package to convert Nix attr. set into TOML. Of course the opposite direction from TOML to Nix is builtins.fromTOML. JSON has the same tooling, you can use pkgs.formats to convert to JSON or you can use builtins to convert from JSON.
But what about YAML? I can convert to YAML using pkgs.formats but how to read YAML?
And is there a way how to do all conversions without creating files (without derivations)? I …
But strangely I can’t find anything about reading INI - which should be much easier than for example TOML that is kind of a supercharged INI…
I also found
lib.generators.toINI but I want to read INI, not to create it
Could you please help how to convert INI plain text to NIX attr. set?
There is no exact definition for ini. It would be impossible to read all possible variations of ini with just one function, but a lot of ini files should work with TOML too. If you can’t read it with
builtins.fromTOML, you have to write your own parser i think.
I can’t use
fromTOML since this works:
but this doesn’t:
and I think that most INI variations don’t use quotes around strings.