# Worker CLI Nix Package
#
# Multi-agent worker coordination CLI for HQ orchestration.
# See docs/releasing-worker.md for how to create releases.
#
# DOTFILES INTEGRATION:
# 1. Copy this file to dotfiles/pkgs/worker/default.nix
# 2. Uncomment the appropriate src option below
# 3. Add to your configuration:
#      worker = pkgs.callPackage ./pkgs/worker {};
#      home.packages = [ worker ];

{ lib
, stdenvNoCC
, fetchurl
, autoPatchelfHook
, stdenv
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "worker";
  version = "0.1.1";

  # Option A: Fetch from skills repo tarball (recommended)
  # Update URL to your git forge's raw file URL
  src = fetchurl {
    url = "https://git.clarun.xyz/dan/skills/raw/branch/master/releases/worker_${finalAttrs.version}_linux_amd64.tar.gz";
    sha256 = "sha256-Kz9PbtsWho2HbO8BFx9tdoDHEuyh1UFL/QIvu9YE/B4=";
  };

  # Option B: Local file (for testing)
  # src = fetchurl {
  #   url = "file:///home/dan/proj/skills/releases/worker_${finalAttrs.version}_linux_amd64.tar.gz";
  #   sha256 = "sha256-Kz9PbtsWho2HbO8BFx9tdoDHEuyh1UFL/QIvu9YE/B4=";
  # };

  sourceRoot = ".";

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    stdenv.cc.cc.lib  # libstdc++
  ];

  dontConfigure = true;
  dontBuild = true;
  dontStrip = true;

  installPhase = ''
    runHook preInstall
    install -Dm755 worker $out/bin/worker
    runHook postInstall
  '';

  meta = with lib; {
    description = "Multi-agent worker coordination CLI for HQ orchestration";
    homepage = "https://github.com/OWNER/skills";
    license = licenses.mit;
    maintainers = [ ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "worker";
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
  };
})
