Can't figure out how to make a Nix package for a Go+C pidgin plugin supposed to be build with cmake

Hi, i’m trying to make a nix package for the plugin purple-gowhatsapp. Normally it should be built with cmake according to the developper, but when i do i get this error:

go: errors parsing go.mod:
/build/source/src/go/go.mod:13:2: require go.mau.fi/whatsmeow: Get "https://proxy.golang.org/go.mau.fi/whatsmeow/@v/list": dial tcp: lookup proxy.golang.org on [::1]:53: read udp [::1]:34681->[::1]:53: read: connection refused
make[2]: *** [src/go/CMakeFiles/purple-go-whatsapp.dir/build.make:97: /build/source/src/go/go.mod] Error 1
make[2]: *** Deleting file '/build/source/src/go/go.mod'
make[1]: *** [CMakeFiles/Makefile2:143: src/go/CMakeFiles/purple-go-whatsapp.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
error: builder for '/nix/store/riyaqhh1ivjkikaglnpqhpygfj2bzrmm-purple-gowhatsapp-1.11.1.drv' failed with exit code 2;
       last 10 log lines:
       > [  8%] Building C object src/go/CMakeFiles/purple-dummy.dir/__/c/constants.c.o
       > [ 12%] Linking C static library libpurple-dummy.a
       > [ 12%] Built target purple-dummy
       > [ 16%] Updating go modules...
       > go: errors parsing go.mod:
       > /build/source/src/go/go.mod:13:2: require go.mau.fi/whatsmeow: Get "https://proxy.golang.org/go.mau.fi/whatsmeow/@v/list": dial tcp: lookup proxy.golang.org on [::1]:53: read udp [::1]:34681->[::1]:53: read: connection refused
       > make[2]: *** [src/go/CMakeFiles/purple-go-whatsapp.dir/build.make:97: /build/source/src/go/go.mod] Error 1
       > make[2]: *** Deleting file '/build/source/src/go/go.mod'
       > make[1]: *** [CMakeFiles/Makefile2:143: src/go/CMakeFiles/purple-go-whatsapp.dir/all] Error 2
       > make: *** [Makefile:136: all] Error 2
       For full logs, run 'nix log /nix/store/riyaqhh1ivjkikaglnpqhpygfj2bzrmm-purple-gowhatsapp-1.11.1.drv'

With the default.nix:

{ lib, stdenv, fetchFromGitHub, pidgin, xosd
, autoreconfHook, pkgs } :

stdenv.mkDerivation rec {
  pname = "purple-gowhatsapp";
  version = "1.11.1";
  src = fetchFromGitHub {
    owner = "hoehermann";
    repo = "purple-gowhatsapp";
    rev = "v${version}";
    sha256 = "sha256-UqxXQfLQAPzZqcE5LqnlY7b3ojWpi13Hkm2vxwR5GWU=";
  };

  installPhase = ''
    make DESTDIR=$out install/strip
  '';

  postInstall = ''
    mkdir -p $out/lib/pidgin
    mv $out/lib/pidgin-osd.{la,so} $out/lib/pidgin
  '';

  nativeBuildInputs = [ pkgs.cmake ];
  buildInputs = with pkgs; [ 
    pidgin
    go
    gcc
    gdk-pixbuf
    opusfile
  ];

  meta = with lib; {
    homepage = "https://github.com/hoehermann/purple-gowhatsapp";
    description = " Pidgin/libpurple plugin for WhatsApp Web. ";
    license = licenses.gpl3;
    platforms = platforms.linux;
  };
}

My guess is that for reproducibility nix doesn’t allow downloading external go modules like this ?

So i tried to first build the go module alone with the following default.nix:

{ lib, stdenv, fetchFromGitHub, pidgin, xosd
, autoreconfHook, pkgs } :

pkgs.buildGoModule rec {
  pname = "purple-gowhatsapp";
  version = "1.11.1";
  src =
    let repo = fetchFromGitHub {
      owner = "hoehermann";
      repo = "purple-gowhatsapp";
      rev = "v${version}";
      sha256 = "sha256-UqxXQfLQAPzZqcE5LqnlY7b3ojWpi13Hkm2vxwR5GWU=";
    };
    in
    "${repo}/src/go";

    vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA=";

    preBuild = ''
      cp ${src}/go.mod.in ${src}/go.mod
     '';

    meta = with lib; {
    homepage = "https://github.com/hoehermann/purple-gowhatsapp";
    description = " Pidgin/libpurple plugin for WhatsApp Web. ";
    license = licenses.gpl3;
    platforms = platforms.linux;
  };
}

The preBuild phase is needed because the go.mod.in file is supposed to be copied to go.mod by cmake. But now here is what happens:

cp: cannot create regular file '/nix/store/5zgd9gds814q5dii4fppmgb8711bsj6s-source/src/go/go.mod': Permission denied
error: builder for '/nix/store/nysbfkl65nc6rw5ddkbsyrjcjyh9p60r-purple-gowhatsapp-1.11.1-go-modules.drv' failed with exit code 1;
       last 7 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/5zgd9gds814q5dii4fppmgb8711bsj6s-source/src/go
       > source root is go
       > patching sources
       > configuring
       > building
       > cp: cannot create regular file '/nix/store/5zgd9gds814q5dii4fppmgb8711bsj6s-source/src/go/go.mod': Permission denied
       For full logs, run 'nix log /nix/store/nysbfkl65nc6rw5ddkbsyrjcjyh9p60r-purple-gowhatsapp-1.11.1-go-modules.drv'.
error: 1 dependencies of derivation '/nix/store/ll8f14cvqa50n8vaw6d3vw9ymicxm6wg-purple-gowhatsapp-1.11.1.drv' failed to build

I don’t get why the build directory is read only now ?

Thanks in advance !

$src is never writable. Build directory is unpacked or copied from it.

Ohhh so i’m supposed to only do cp go.mod.in go.mod… I gues i’m too used to arch’s PKGBUILD haha

now i get the error $GOPATH/go.mod exists but should not, i have no idea why is so i guess i’ll have to go learn how go works first. Thanks!

I don’t know the stuff, so I’ll just throw a link in case you’ve missed it: