Building a c .a/.so from go

Hi friends,

I’d like to use a go library in haskell. :new_moon_with_face:

Can someone help me how to build the .a and/or .so file from go? I got it working manually by running go build -buildmode=c-archive -o bubbletea.a main.go and then referencing that from haskell, but my haskell derivation wants the package as input, so I need a nix derivation to build this file.

I have tried the following:

pkgs.buildGoModule {
    name = "bubbletea";
    src = ./golang;
    vendorHash = null;
    buildPhase = ''
    go build -trimpath -buildmode=c-archive -o libbubbletea.a $src/main.go
    installPhase = ''
    mkdir $out
    cp libbubbletea.a $out/

This complains with

error: output '/nix/store/d24j89cjs6j0hm9v9597f870yil1p5qd-bubbletea' is not allowed to refer to the following paths:

Has anyone tried this? Am I even looking the right way?