Nix-to-Config File

Table of Contents

1. Overview

This page is intended to be a cheat sheet for creating a config file of any format in any place. This page will cover:

  • A minimal example in Nix needed to create a config file in a specific place
  • A minimal example in Nix for each grammar primitive for each config file format
  • Potential quirks

2. YAML

3. JSON

4. .ini

5. KDL

This has a rather complex structure that cannot easily be represented in a key-value pair format.

6. TOML

7. XML

8. Bonus: Testing Nix-to-Config Quickly

Use the nix repl tool to immediately evaluate a Nix expression, and see how it would come out without rebuilding things.

nix-repl> let pkgs = (import <nixpkgs> {}); in pkgs.lib.generators.toJSON {} {a = 3;}
"{\"a\":3}"

Created: 2025-10-29 Wed 13:02

Validate