Need help to package slidge-whatsapp

As a amateur, I am not familiar to package software written in mixed language like this. (python and go). And I have little to zero knowledge in both language.

How do I handle this?

https://codeberg.org/slidge/slidge-whatsapp/src/commit/2987788ef37fad34532c5466449974bb6fe506ed/build.py#L56-L80

To build the go parts, It requires gopy and goimports as dependencies.

goimports is in the gotools packages in nixpkgs.

I am able to package gopy by following instructions in nixpkgs manual.

{
  buildGoModule,
  fetchFromGitHub,
  ...
}:
{
  gopy = buildGoModule (finalAttrs: {
    pname = "gopy";
    version = "master";

    src = fetchFromGitHub {
      owner = "go-python";
      repo = "gopy";
      rev = "72557f647208599c726c14dc9721a6c850d2e6d9";
      hash = "sha256-FSAxadu9ZAX7Ep2wHegIzQcGO8PSCa5b4aPtRrHRnJw=";
    };

    vendorHash = "sha256-J0Xmgk9YGUNkw7q97RgElgAVSZv5HTLDdsPtmaAaXAM=";

    checkFlags =
      let
        skippedTests = [
          # Requires network access (Error: module lookup disabled by GOPROXY=off).
          "TestGovet"

          "TestGofmt"
          "TestGoPyErrors"
        ];
      in
      [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ];

    meta = {
      mainProgram = "gopy";
    };
  });
}

Manually running the gopy command to build go parts seems to work somhow (with some error) in nix-shell environment with gopy and gotools installed. However I do not know how to write it in nix expression to package sligde-whatsapp.

1 Like

Did you make any progress?

Yesterday I found I can build the package with devenv environment with uv package and just run uv build to build it from source in codeberg easily, then I can get a .whl file inside a dist folder.

However I cannot able to do it in nix way, as manually running the gopy build command in the build.py file outside the uv build environment do not work. It throws error about something like this: # github.com/gen2brain/go-fitz | /go/pkg/mod/github.com/gen2brain/go-fitz@v1.18.0/fitz.go:8:10: fatal error: mupdf/fitz.h: No such file or directory · Issue #41 · gen2brain/go-fitz · GitHub

Not only that, doing it in buildGoModule don’t work in another way because it do not have internet access i guess because of GOPROXY=off issue. Manually setting GOPROXY to point to some manually crafted goModules also not help.

Today I learned what .whl actually is as I don’t know much about python, and I figured out fetchPypi can fetch wheel and not the source, so I came up another way to package it.

{
  fetchPypi,
  python3Packages,
  python3,
  ...
}:
let
  # from pkgs/development/python-modules/clarifai-protocol/default.nix
  pythonVersionNoDot = builtins.replaceStrings [ "." ] [ "" ] python3.pythonVersion;
in
python3Packages.buildPythonPackage (finalAttrs: {
  pname = "slidge-whatsapp";
  version = "0.3.11";
  format = "wheel";

  src = fetchPypi {
    format = "wheel";
    pname = "slidge_whatsapp";
    version = finalAttrs.version;
    python = "cp${pythonVersionNoDot}";
    abi = "cp${pythonVersionNoDot}";
    dist = "cp${pythonVersionNoDot}";
    platform = "manylinux_2_41_x86_64";
    hash = "sha256-SbnRWbp2xnBg5lSNMUqwZZ0NzLQg+pOg+51LzSFr5bY=";
  };

  propagatedBuildInputs = [
    (import ../slidge)
    (import ../linkpreview)
  ];

  meta = {
    # #...
  };
})

I just switch the src with my local build .whl file.

Dependencies slidge and linkpreview need to be packaged, which is not hard. I also got help to package slidge yesterday here; Need help for packaging python package (package not installed error)

I am now just able to get ./result/bin/slidge-whatsapp to show some proper help message, but I have to set things up to see if it actually works.

Oh just noticed people is packaging matridge and some dependencies are overlapped.

Solved.
To build from source instead of wheel, gopy need to be patch to use -mod=vendor instead of hardcoded -mod=mod.
Had some basic test it seems working. But still need to deploy to production environment to test thing out.
Will submit PR when its dependency slidge is merged.