From 2c44fddcb44e013114c8d0d9a669c0ec91d4d7b8 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Tue, 31 Mar 2026 15:47:10 -0500 Subject: no more copilot-api --- modules/services/nixos/copilot-api.nix | 62 ----------------------- modules/services/nixos/default.nix | 1 - modules/services/options.nix | 19 ------- pkgs/copilot-api/default.nix | 93 ---------------------------------- secrets.nix | 1 - 5 files changed, 176 deletions(-) delete mode 100644 modules/services/nixos/copilot-api.nix delete mode 100644 pkgs/copilot-api/default.nix diff --git a/modules/services/nixos/copilot-api.nix b/modules/services/nixos/copilot-api.nix deleted file mode 100644 index d9d4da3..0000000 --- a/modules/services/nixos/copilot-api.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - cfg = config.collinux.services.copilot-api; -in { - config = lib.mkIf cfg.enable { - users.groups."copilot-api" = {}; - users.users."copilot-api" = { - isSystemUser = true; - group = "copilot-api"; - home = "/var/lib/copilot-api"; - createHome = true; - }; - - systemd.services."copilot-api" = { - description = "GitHub Copilot API Proxy"; - restartIfChanged = true; - wants = ["network-online.target"]; - after = ["network-online.target"]; - wantedBy = ["multi-user.target"]; - - serviceConfig = { - User = "copilot-api"; - Group = "copilot-api"; - Type = "simple"; - Restart = "on-failure"; - RestartSec = "5s"; - - # Load environment variables from file (e.g., GH_TOKEN) - EnvironmentFile = lib.mkIf (cfg.githubToken != null) cfg.githubToken; - - # Security hardening - PrivateTmp = true; - ProtectSystem = "strict"; - ProtectHome = true; - NoNewPrivileges = true; - PrivateDevices = true; - ProtectKernelTunables = true; - ProtectControlGroups = true; - RestrictSUIDSGID = true; - - # Allow writing to state directory - StateDirectory = "copilot-api"; - WorkingDirectory = "/var/lib/copilot-api"; - - ExecStart = let - copilot-api = pkgs.callPackage ../../../pkgs/copilot-api {}; - # Use bash to read token from environment and pass to command - startScript = pkgs.writeShellScript "copilot-api-start" '' - exec ${copilot-api}/bin/copilot-api start \ - --port ${toString cfg.port} \ - --host ${cfg.listenAddr} \ - ${lib.optionalString (cfg.githubToken != null) "--github-token \"$GH_TOKEN\""} - ''; - in "${startScript}"; - }; - }; - }; -} diff --git a/modules/services/nixos/default.nix b/modules/services/nixos/default.nix index 3533908..d0e170c 100644 --- a/modules/services/nixos/default.nix +++ b/modules/services/nixos/default.nix @@ -15,6 +15,5 @@ ./minecraft.nix ./copyparty.nix ./qbittorrent.nix - ./copilot-api.nix ]; } diff --git a/modules/services/options.nix b/modules/services/options.nix index 70fd695..0484b6b 100644 --- a/modules/services/options.nix +++ b/modules/services/options.nix @@ -157,24 +157,5 @@ in { example = "/run/secrets.d/caddy-env"; }; }; - - copilot-api = { - enable = mkEnableOption "GitHub Copilot API proxy"; - listenAddr = mkOption { - description = "Address to listen on"; - type = ipAddr; - default = "127.0.0.1"; - }; - port = mkOption { - description = "Port to listen on"; - type = types.port; - default = 4141; - }; - githubToken = mkOption { - description = "Path to file containing GitHub token"; - type = types.nullOr types.str; - default = null; - }; - }; }; } diff --git a/pkgs/copilot-api/default.nix b/pkgs/copilot-api/default.nix deleted file mode 100644 index a66fe1a..0000000 --- a/pkgs/copilot-api/default.nix +++ /dev/null @@ -1,93 +0,0 @@ -{ - 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 - ''; - } diff --git a/secrets.nix b/secrets.nix index 67ab5fd..a46e065 100644 --- a/secrets.nix +++ b/secrets.nix @@ -8,5 +8,4 @@ in { "hosts/ganymede/secrets/collin-copyparty-password.age".publicKeys = [mercury.host_pubkey ganymede.host_pubkey]; "hosts/ganymede/secrets/collin-forgejo-password.age".publicKeys = [mercury.host_pubkey ganymede.host_pubkey]; "hosts/ganymede/secrets/wireguard-pk.age".publicKeys = [ganymede.host_pubkey]; - "hosts/ganymede/secrets/copilot-token.age".publicKeys = [ganymede.host_pubkey]; } -- cgit v1.3.1