From 9561853d2c5c18749dd7d8d3eca25a360e2d8dfe Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Fri, 6 Mar 2026 09:34:57 -0600 Subject: Add copilot-api package and service - Package copilot-api (GitHub Copilot API proxy) using bun - Create systemd service module for copilot-api - Enable service on ganymede listening on localhost:4141 - Add SSH port forwarding from mercury to ganymede for copilot-api - Update gitignore to exclude Claude Code artifacts Co-Authored-By: Claude (claude-sonnet-4.5) --- pkgs/copilot-api/default.nix | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 pkgs/copilot-api/default.nix (limited to 'pkgs/copilot-api') diff --git a/pkgs/copilot-api/default.nix b/pkgs/copilot-api/default.nix new file mode 100644 index 0000000..a66fe1a --- /dev/null +++ b/pkgs/copilot-api/default.nix @@ -0,0 +1,93 @@ +{ + pkgs, + lib, + ... +}: let + inherit (pkgs) stdenv bun makeBinaryWrapper fetchFromGitHub; + + node_modules = stdenv.mkDerivation { + pname = "copilot-api-node_modules"; + version = "0.7.0"; + + src = fetchFromGitHub { + owner = "ericc-ch"; + repo = "copilot-api"; + tag = "v0.7.0"; + hash = "sha256-rUUqf9QalVZDN3aw9ze5Uh+y5xvH6zdSgGN6ZLDjkDQ="; + }; + + nativeBuildInputs = [bun]; + + impureEnvVars = lib.fetchers.proxyImpureEnvVars; + dontPatchShebangs = true; + + patchPhase = '' + # Remove prepare script that tries to setup git hooks + sed -i '/"prepare":/d' package.json + ''; + + buildPhase = '' + runHook preBuild + export HOME=$TMPDIR + bun install --no-progress --frozen-lockfile + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out + cp -R ./node_modules $out + runHook postInstall + ''; + + outputHash = "sha256-+AH8eRG3SwwU86Pa/hFSW5nWD0v1po6z7xoLKUzq3qY="; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + }; +in + stdenv.mkDerivation { + pname = "copilot-api"; + version = "0.7.0"; + + src = fetchFromGitHub { + owner = "ericc-ch"; + repo = "copilot-api"; + tag = "v0.7.0"; + hash = "sha256-rUUqf9QalVZDN3aw9ze5Uh+y5xvH6zdSgGN6ZLDjkDQ="; + }; + + nativeBuildInputs = [makeBinaryWrapper]; + buildInputs = [bun pkgs.nodejs]; + + configurePhase = '' + runHook preConfigure + # Don't copy node_modules - let bun install them fresh + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + export HOME=$TMPDIR + # Use the cached node_modules + cp -R ${node_modules}/node_modules . + chmod -R +w node_modules + # Try using bun's native build with correct entry point + mkdir -p dist + ${bun}/bin/bun build src/main.ts --outdir dist --target bun --format esm --sourcemap + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/lib/copilot-api + cp -r dist node_modules package.json $out/lib/copilot-api/ + + mkdir -p $out/bin + makeWrapper ${bun}/bin/bun $out/bin/copilot-api \ + --prefix PATH : ${lib.makeBinPath [bun]} \ + --add-flags "$out/lib/copilot-api/dist/main.js" + + runHook postInstall + ''; + } -- cgit v1.3.1