farcaller / gonix

Go bindings to nix API
https://pkg.go.dev/github.com/farcaller/gonix
Apache License 2.0
28 stars 1 forks source link

Build fails with Nix 2.24 #3

Open cottand opened 1 month ago

cottand commented 1 month ago

I building a Go app using gonix, and since Nix 2.24 the build fails. Build logs:

Building subPackage ./cmd/nixmad
# github.com/farcaller/gonix
In file included from vendor/github.com/farcaller/gonix/err.go:7:
/nix/store/rvmcklls1zdxj9wjyxvpn92gl5ql8gml-nix-2.24.6-dev/include/nix/nix_api_value.h:41:2: error: expected expression
[[deprecated("use nix_value instead")]] typedef nix_value Value;
 ^
/nix/store/rvmcklls1zdxj9wjyxvpn92gl5ql8gml-nix-2.24.6-dev/include/nix/nix_api_value.h:41:41: error: expected identifier or '('
[[deprecated("use nix_value instead")]] typedef nix_value Value;

I suspect this is due to breaking changes in the C API in Nix 2.24, see https://github.com/NixOS/nix/commit/b94e1d62182114ab5198fd58869a9af29d54cff5

You can reproduce this by running:

nix build "github:cottand/selfhosted/d0f8c22e83bcac8211beedb630cde1454a52f3e8#nixmad" -L

(build here)

Pinning Nix at 2.23 with buildInputs = [ nixVersions.nix_2_23 ] fixes this.

Otherwise wanted to say thanks for this! Makes using Nix from Go much, much easier :)

cottand commented 1 month ago

During builds, I have also seen:

> vendor/github.com/farcaller/gonix/gonix.go:69:10: could not determine kind of name for C.nix_init_plugins

with nixVersions.latest

farcaller commented 1 month ago

Yeah, it's unfortunately a moving target. I verified it working with the nix pinned inside the flake of this repo, and you should be safe to use it, but unfortunately there's not much we can do other than to play chase for now.

cottand commented 1 month ago

No worries, I understand this is expected as the C API is not stable yet.

I do suggest you either update the README from "the one available on master" to "the one in Nix 2.18-2.23", so that it is clear that pinning is necessary. Otherwise it reads like this repo is trying to keep track of the moving target, which it understandably is not.

farcaller commented 1 month ago

Good point, added the notice in cfc578737eca667c929d294d3a53ae0784f2ccdc.