diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-03-06 09:34:57 -0600 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-03-06 12:00:17 -0600 |
| commit | 9561853d2c5c18749dd7d8d3eca25a360e2d8dfe (patch) | |
| tree | 697e4bfc4a1f14d72f082f11c7a7b92fdecd0061 /modules/services/nixos/copilot-api.nix | |
| parent | e4a00e31c5a0a343749963598fa5d7faa49d60c1 (diff) | |
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) <noreply@anthropic.com>
Diffstat (limited to 'modules/services/nixos/copilot-api.nix')
| -rw-r--r-- | modules/services/nixos/copilot-api.nix | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/modules/services/nixos/copilot-api.nix b/modules/services/nixos/copilot-api.nix new file mode 100644 index 0000000..d9d4da3 --- /dev/null +++ b/modules/services/nixos/copilot-api.nix @@ -0,0 +1,62 @@ +{ + 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}"; + }; + }; + }; +} |
