Packaging binary for multiple architectures

I want to package gh-copilot, but it is closed source and only pre-built binaries on release page are available. Anyway, I managed to package them like this:

{ stdenv
, lib
, fetchurl
, system
}:
let
  systemToBinary = {
    "x86_64-linux" = {
      name = "linux-amd64";
      hash = "12mysfa84fzq3f95mi6i46yrcbdl3y91sn53snr4qqhm2w8yzb0l";
    };
    "aarch64-linux" = {
      name = "linux-arm64";
      # ...
    };
    # ...
  };
in
stdenv.mkDerivation rec {
  # ...
  src = fetchurl {
    name = "gh-copilot";
    url = "https://github.com/github/gh-copilot/releases/download/v${version}/${systemToBinary.${system}.name}";
    sha256 = systemToBinary.${system}.hash;
  };
  # ...
  installPhase = ''
    install -m755 -D $src $out/bin/gh-copilot
  '';
  # ...
}

But OfBorg can’t build it because there is no system argument. I could hard-code support only for x86_64-linux, but the original package request asked for macOS support.

So my question is: how can I package pre-built binaries for multiple architectures?

Use stdenv.hostPlatform.system. For example, the VS Code derivation uses it to support different platforms.

1 Like