{ lib, stdenv, autoPatchelfHook, fetchurl, makeBinaryWrapper, bash, versionCheckHook, }: let sources = lib.importJSON ./sources.json; srcConfig = sources.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); in stdenv.mkDerivation (finalAttrs: { pname = "github-copilot-cli"; inherit (sources) version; src = fetchurl { url = "https://github.com/github/copilot-cli/releases/download/v${finalAttrs.version}/${srcConfig.name}.tar.gz"; inherit (srcConfig) hash; }; nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ]; sourceRoot = "."; dontStrip = true; installPhase = '' runHook preInstall # Use libexec to preserve filename when calling makeBinaryWrapper install -Dm755 copilot $out/libexec/copilot runHook postInstall ''; postInstall = '' # Filename must explictly be "copilot" for internal self-referencing makeWrapper $out/libexec/copilot $out/bin/copilot \ --add-flags "--no-auto-update" \ --prefix PATH : "${lib.makeBinPath [ bash ]}" ''; nativeInstallCheckInputs = [ versionCheckHook ]; doInstallCheck = !stdenv.hostPlatform.isDarwin; # skip on Darwin - OpenSSL errors in sandbox passthru.updateScript = ./update.sh; meta = { description = "GitHub Copilot CLI brings the power of Copilot coding agent directly to your terminal"; homepage = "https://github.com/github/copilot-cli"; changelog = "https://github.com/github/copilot-cli/releases/tag/v${finalAttrs.version}"; license = lib.licenses.unfree; maintainers = with lib.maintainers; [ dbreyfogle ]; mainProgram = "copilot"; platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; }; })