So I am still pretty new to nix, but I am loving it so far.
At work, I was working on some AWS stuff, and I had to set up a cloudformation template. As I was doing that, I was struck by how similar the cloudformation JSON template is to the Nix expression language. Both are declarative and describe a set of resources (software on a machine on one hand, and AWS resources on the other hand).
The next thought I had was: would it be possible to use nix to do cloudformation? That would be pretty neat, instead of this DSL-JSON-frankenstein that is cloudformation.
I’m still a newbie so I couldn’t really think beyond there. I thought I would ask on here. Am I incorrect in identifying the similarity? Would it be possible to nix-ify cloudformation?
Sure. You can write a Nix module that produces a JSON file. If you want added benefits beyond simple type-checking, you should have a look at Nickel: Nickel 1.0 release
I was facing similar problems, so I created a project to make my life harder.
Then I discovered Nix, had same thought as you.
That is why I created modules to devshell to generate files (devshell-files). You could create a similar project with devenv, but PR with modules to CloudFormation would be welcome.
Hint:
Both with python and CUE failed to read CloudFormation YAML or some especial features of YAML. I think they use some kind of extended YAML. But you can read a JSON and YAML from Nix with: