A Nix library that parses Zig Object Notation (ZON) into native Nix data structures. This allows you to easily read build.zig.zon files within your Nix expressions, making it easier to package Zig projects by extracting dependencies and metadata directly from the source.
Although zon2nix covers the needs of most ziglings, nix-from-zon is useful for accessing package metadata from Nix code, which zon2nix doesn't facilitate. The most significant use case is accessing the package version from build.zig.zon to use it inside mkDerivation or other Nix expressions.
Takes a ZON string and returns a corresponding Nix value analogous to builtins.fromJSON.
let
inherit (nix-from-zon.lib) fromZON;
data = fromZON ''
.{
.name = "demo",
.dependencies = .{
.zls = .{
.url = "https://...",
},
},
.paths = .{ "src", "README.md" },
}
'';
in
# data is:
# {
# name = "demo";
# dependencies = {
# zls = { url = "https://..."; };
# };
# paths = [ "src" "README.md" ];
# }- Structs
.{ .a = false }->{ a = false; } - Tuples
.{ 1, 2 }->[ 1 2 ] - [-] Strings <- github really should have a pending marker
- Basic strings with
\t,\n,\r - Byte and unicode values (
\x,\u)
- Basic strings with
- Booleans
- Null
-
nanandinf:{ _type = "float"; value = "nan"; } - Enums
.foo->{ _type = "enum"; value = "foo"; } - Quoted identifiers
@"foo" - Numbers
- Multiline strings
- Comments (they are simply ignored)
To run the test suite:
nix flake check