Go bindings to nix

I’ve finally finished the Go bindings to nix that use the proposed C API. Feel free to check the code, docs, and try it in action.

All the bits seem to be functional, including evaluations, builds, and exposing both functions and values in go into the nix scope.

11 Likes

Nice! For others, here’s the experimental C bindings PR (Towards) stable C bindings for libutil, libexpr by yorickvP · Pull Request #8699 · NixOS/nix · GitHub by @yorickvP

3 Likes

Looks great! But it may make confusion with GitHub - nix-community/go-nix: Elements of Nix re-implemented as Go libraries [maintainer=@flokli], a go implementation of Nix.

Just stumbled across this. It seems the mentioned C bindings PR was merged, does that mean we can use the go bindings (and also the mentionend python bindings) with current nix versions?

I’ve been working on some go programs that interact with nix and would love to replace the hacky exec() calls with proper bindings to interact with nix from go code.

Would be interested in an update!

1 Like

It’s not wrong to program against the CLI.
A downside of bindings is that you’re linking against a specific Nix version that’s not the system version or the version that’s normally used with your store.
Multiple versions generally work well together, but it can be surprising to users nonetheless, just to see that a feature is not available, and that kind of thing.

1 Like