Skip to content

joo-was-already-taken/nix-from-zon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nix-from-zon

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.

Use Cases

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.

API

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" ];
  # }

Supported Features

  • 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)
  • Booleans
  • Null
  • nan and inf: { _type = "float"; value = "nan"; }
  • Enums .foo -> { _type = "enum"; value = "foo"; }
  • Quoted identifiers @"foo"
  • Numbers
  • Multiline strings
  • Comments (they are simply ignored)

Development

To run the test suite:

nix flake check

About

A Nix library that parses Zig Object Notation (ZON) into native Nix data structures.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages