Files

85 lines
2.3 KiB
Nix

{
lib,
buildGoModule,
fetchFromGitHub,
}:
buildGoModule rec {
pname = "codex-oauth-proxy";
version = "1.1.1";
src = fetchFromGitHub {
owner = "dvcrn";
repo = "codex-oauth-proxy";
# Upstream tags are bare semver, without the "v" prefix.
rev = version;
hash = "sha256-WZN+OVvK5/R46Ko01jw4m9jI9BcvpZzxWifcui90/g4=";
};
vendorHash = "sha256-hb0rGd+HZHSV/sLXiIa7LPkXVuRqdXrQHZxM4v5sgvs=";
# 1.1.1 rewrites gpt-6.1-terra to gpt-5.5, which ChatGPT accounts reject.
# Drop once upstream lists the model in normalizeModel.
patches = [ ./gpt-6.1-terra.patch ];
env.CGO_ENABLED = 0;
# cmd/codex-oauth-proxy-worker and parts of internal/server are js && wasm
# Cloudflare Worker code needing syscall/js, so only the server is buildable.
subPackages = [ "cmd/codex-oauth-proxy" ];
# The Nix source tree has no .git, so Go's VCS stamping fails without it.
# Set before the build and check phases, which both call `go`.
preConfigure = ''
export GOFLAGS="$GOFLAGS -buildvcs=false"
'';
ldflags = [
"-s"
"-w"
];
# Upstream CI runs `go test -v ./...` and the suite only uses httptest and
# t.Setenv, so it needs neither network nor credentials. The default check
# phase would reuse subPackages and test only the server, hence the override.
doCheck = true;
checkPhase = ''
runHook preCheck
# Tests may read assets relative to their package directory.
export GOFLAGS=''${GOFLAGS//-trimpath/}
go test -v ./...
runHook postCheck
'';
postInstall = ''
install -Dm644 ${./codex-oauth-proxy.service} \
"$out/lib/systemd/user/codex-oauth-proxy.service"
substituteInPlace "$out/lib/systemd/user/codex-oauth-proxy.service" \
--replace-fail '@out@' "$out"
'';
passthru = {
category = "AI LLM Gateway";
updateScript = [
"nix-update"
"--flake"
".#codex-oauth-proxy"
];
};
meta = {
description = "Local proxy exposing a ChatGPT Codex account through OpenAI-compatible APIs";
homepage = "https://github.com/dvcrn/codex-oauth-proxy";
changelog = "https://github.com/dvcrn/codex-oauth-proxy/releases/tag/${version}";
license = lib.licenses.mit;
sourceProvenance = with lib.sourceTypes; [ fromSource ];
mainProgram = "codex-oauth-proxy";
platforms = lib.platforms.unix;
maintainers = [ ];
};
}