{"id":23819773,"url":"https://github.com/theobori/nix-converter","last_synced_at":"2026-05-05T13:32:57.875Z","repository":{"id":270393867,"uuid":"907587242","full_name":"theobori/nix-converter","owner":"theobori","description":"All-in-one converter configuration language to Nix and vice versa","archived":false,"fork":false,"pushed_at":"2025-01-26T15:52:40.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T16:31:49.290Z","etag":null,"topics":["configuration-language","data-format","json","nix","toml","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theobori.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-23T23:57:08.000Z","updated_at":"2025-01-26T15:52:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"73a92bc1-a820-494c-b1e2-3bdf0b53d260","html_url":"https://github.com/theobori/nix-converter","commit_stats":null,"previous_names":["theobori/nix-converter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fnix-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fnix-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fnix-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theobori%2Fnix-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theobori","download_url":"https://codeload.github.com/theobori/nix-converter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100517,"owners_count":19747683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration-language","data-format","json","nix","toml","yaml"],"created_at":"2025-01-02T07:15:10.485Z","updated_at":"2026-05-05T13:32:57.820Z","avatar_url":"https://github.com/theobori.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nix data format converter\n\n[![build](https://github.com/theobori/nix-converter/actions/workflows/build.yml/badge.svg)](https://github.com/theobori/nix-converter/actions/workflows/build.yml)\n\n[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org)\n\nThis GitHub repository is a toy project in the form of a CLI tool. It allows you to convert a data format, such as JSON, into Nix, and vice versa.\n\nThe project is based on various projects that provide a parser. Here are the references.\n- [go-nix](https://github.com/orivej/go-nix) for parsing the Nix language.\n- [fastjson](https://github.com/valyala/fastjson) for parsing the JSON language.\n- [yaml.v3](https://gopkg.in/yaml.v3) for parsing the YAML language.\n- [pelletier/go-toml](https://github.com/pelletier/go-toml) for parsing the TOML language.\n- [BurntSushi/toml](https://github.com/BurntSushi/toml) providing a TOML marshaller.\n\nAST traversal for the Nix language remains static; Nix expressions are not evaluated.\n\n## Supported languages\n\nThe following languages are supported.\n\n| Language | To Nix | From Nix |\n| - | - | - |\n| **JSON** | Yes | Yes |\n| **YAML** | Yes | Yes |\n| **TOML** | Yes (unstable output) | Yes |\n\nThe YAML evaluation support anchors. They are handled during the YAML to Nix conversion.\n\n## Getting started\n\nTo start using the tool, simply run the following command.\n\n```bash\nnix-converter -help\n```\n\nBy default, every generated hashmap key strings are protected, it means they are surrounded by double quotes, to avoid this behavior you can use the `-unsafe-keys` CLI flag.\n\n## Examples\n\nHere are a few examples of how to use the tool.\n\n### From Nix to JSON using the standard input\n```bash\necho -n \"{a = [1 2 3];}\" | nix-converter -from-nix -l json\n```\n\n### From YAML to Nix using a file named `a.yaml`\n```yaml\n# a.yaml\n- 0\n- 1\n- - 2\n  - - 3\n    - - 4\n      - - 5\n        - 6\n        - 7\n        - 8\n```\n\n```bash\nnix-converter -f a.yaml -l yaml\n```\n\nIt is also possible to use multiple UNIX pipe.\n```bash\nnix-converter -f a.yaml -l yaml | nix-converter -from-nix -l json\n```\n\n### From YAML to Nix with anchor using a file named `anchor.yaml`\n```yaml\n# anchor.yaml\ndefinitions:\n  steps:\n    - step: \u0026build-test\n        name: Build and test\n        script:\n          - mvn package\n        artifacts:\n          - target/**\npipelines:\n  branches:\n    develop:\n      - step: *build-test\n    main:\n      - step: *build-test\n```\n\n```bash\nnix-converter -f anchor.yaml -l yaml\n```\n\n### From Nix to YAML using a file named `a.nix`\n```nix\n# a.nix\n{\n  id = \"1c7d8e9f0\";\n  users = [\n    {\n      name = \"Alice and her cats\";\n      age = 2.8;\n      \"pets\" = [\n        {\n          type = \"321a\";\n          name = \"Luna\";\n          toys = [ ];\n          hello = { };\n        }\n        {\n          type = \"dog\";\n          name = \"Max\";\n        }\n      ];\n    }\n    {\n      name = \"Bob\";\n      age = 34;\n      pets = null;\n    }\n  ];\n  settings = {\n    theme = {\n      dark = {\n        primary = \"#1a1a1a\";\n        accent = \"#4287f5\";\n      };\n      light = {\n        primary = \"#ffffff\";\n        accent = \"#2196f3\";\n      };\n    };\n    notifications = true;\n  };\n  meta = {\n    created = \"2024-01-01\";\n    modified = {\n      by = \"system\";\n      timestamp = \"2024-02-15T14:30:00Z\";\n    };\n  };\n}\n```\n\n```bash\nnix-converter -from-nix -f a.nix -l yaml\n```\n\n### From YAML to Nix using a file named `anchor.yaml` with iterators sorting\n```yaml\n# anchor.yaml\ndefinitions:\n  steps:\n    - step: \u0026build-test\n        c: Build and test\n        b:\n          - mvn3 package\n          - mvn2 package\n          - mvn package\n        a:\n          - -1\n          - 1\npipelines:\n  branches:\n    v: -1.123\n    main:\n      - step: *build-test\n```\n\n```bash\nnix-converter -f anchor.yaml -l yaml -sort-iterators \"all\"\n# or\nnix-converter -f anchor.yaml -l yaml -sort-iterators \"list,hashmap\"\n```\n\n### Get a Go value from Nix\n\n```go\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/theobori/nix-converter/converter/nix\"\n)\n\nfunc main() {\n\tnixString := `\n{\n  meta = {\n    created = \"2024-01-01\";\n    modified = {\n      by = \"system\";\n      timestamp = \"2024-02-15T14:30:00Z\";\n    };\n  };\n  id = \"1c7d8e9f0\";\n}`\n\t// Here we should get a Go map, map[string]any\n\tv, err := nix.GoValue(nixString)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Printf(\"%t\\n\", v)\n}\n```\n\n## Contribute\n\nIf you want to help the project, you can follow the guidelines in [CONTRIBUTING.md](./CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheobori%2Fnix-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheobori%2Fnix-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheobori%2Fnix-converter/lists"}