Universal Nix AST to multi-language code generator. Describe a program once in Nix; emit idiomatic code in any target language.
Nix serves as the intermediate representation (IR). Generator backends are pure functions that traverse the AST and emit target-language strings.
let
nxgen = builtins.getFlake "github:0nybl/nxgen";
ast = nxgen.lib.ast;
types = nxgen.lib.types;
py = nxgen.generators.python { inherit ast types; };
ts = nxgen.generators.typescript { inherit ast types; };
program = ast.module {
body = [
(ast.defun {
name = "add";
args = [{ name = "a"; type = types.int; } { name = "b"; type = types.int; }];
returns = types.int;
body = [(ast.return_ (ast.binop "+" (ast.var "a") (ast.var "b")))];
})
];
};
in {
python = py.render program;
typescript = ts.render program;
}Add to your flake inputs:
inputs.nxgen.url = "github:0nybl/nxgen";Then use nxgen.lib.ast, nxgen.lib.types, and nxgen.generators.*.
Any flake that exports nxgenGenerator with name and render fields is a valid backend:
inputs.nxgen-ruby.url = "github:someone/nxgen-ruby";Find community generators on GitHub with the nxgen-generator topic.
nix flake check # run tests
nix develop # enter dev shellMIT