add nix-instantiate

master
Ingolf Wagner 2018-12-05 22:17:28 +01:00
parent 4726f98d85
commit 95208e7931
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
---
title: "nix-instantiate"
date: 2018-12-05T19:09:36+02:00
draft: true
tags:
- NixOS
- Ansible
- Terraform
summary: >
a tool to create your JSON generator.
---
# nix-instantiate
I like NixOS and the way modules work.
I miss it when I do tasks in other languages,
which have less power than NixOS, for example
[Ansible](https://www.ansible.com) and [Terraform](https://www.terraform.io).
Luckily all these tools can be configured via JSON,
and Nix can easily create JSON.
The tool go to tool for that job is
[nix-instantiate](https://nixos.org/nix/manual/#sec-nix-instantiate)
which every NixOS has installed (yeye!).
## First tests
Lets look what `nix-instantiate` does.
We create a file `test1.nix`
```nix
# file test1.nix
rec {
x = "hallo";
y = x;
}
```
and than we run `nix-instantiate` to render json
```sh
$> nix-instantiate --eval --json --strict test1.nix | jq
{
"x": "hallo",
"y": "hallo"
}
```
Nice! this is expected because it is an example from
[the documentation](https://nixos.org/nix/manual/#sec-nix-instantiate).
## Modules for the win
Modules are one of the things that make NixOS really awesome.
So lets us them in combination with `nix-instantiate`!
... todo write more