{ lib, stdenv, rustPlatform, fetchFromGitHub, installShellFiles, clang, cmake, gitMinimal, libclang, makeBinaryWrapper, nix-update-script, pkg-config, openssl, ripgrep, versionCheckHook, installShellCompletions ? stdenv.buildPlatform.canExecute stdenv.hostPlatform, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "codex"; version = "0.92.0"; src = fetchFromGitHub { owner = "openai"; repo = "codex"; tag = "rust-v${finalAttrs.version}"; hash = "sha256-m/g+5wdehyaHDw6i5vik4HXiisY/iWFtPX0gKjCFPNY="; }; sourceRoot = "${finalAttrs.src.name}/codex-rs"; cargoHash = "sha256-fuT8vPb9/7fZam129nR6y+r+3j46WBhlf73Htkcjpzc="; nativeBuildInputs = [ clang cmake gitMinimal installShellFiles makeBinaryWrapper pkg-config ]; buildInputs = [ libclang openssl ]; # NOTE: set LIBCLANG_PATH so bindgen can locate libclang, and adjust # warning-as-error flags to avoid known false positives (GCC's # stringop-overflow in BoringSSL's a_bitstr.cc) while keeping Clang's # character-conversion warning-as-error disabled. env = { LIBCLANG_PATH = "${lib.getLib libclang}/lib"; NIX_CFLAGS_COMPILE = toString ( lib.optionals stdenv.cc.isGNU [ "-Wno-error=stringop-overflow" ] ++ lib.optionals stdenv.cc.isClang [ "-Wno-error=character-conversion" ] ); }; # NOTE: part of the test suite requires access to networking, local shells, # apple system configuration, etc. since this is a very fast moving target # (for now), with releases happening every other day, constantly figuring out # which tests need to be skipped, or finding workarounds, was too burdensome, # and in practice not adding any real value. this decision may be reversed in # the future once this software stabilizes. doCheck = false; postInstall = lib.optionalString installShellCompletions '' installShellCompletion --cmd codex \ --bash <($out/bin/codex completion bash) \ --fish <($out/bin/codex completion fish) \ --zsh <($out/bin/codex completion zsh) ''; postFixup = '' wrapProgram $out/bin/codex --prefix PATH : ${lib.makeBinPath [ ripgrep ]} ''; doInstallCheck = true; nativeInstallCheckInputs = [ versionCheckHook ]; passthru = { updateScript = nix-update-script { extraArgs = [ "--version-regex" "^rust-v(\\d+\\.\\d+\\.\\d+)$" ]; }; }; meta = { description = "Lightweight coding agent that runs in your terminal"; homepage = "https://github.com/openai/codex"; changelog = "https://raw.githubusercontent.com/openai/codex/refs/tags/rust-v${finalAttrs.version}/CHANGELOG.md"; license = lib.licenses.asl20; mainProgram = "codex"; maintainers = with lib.maintainers; [ malo delafthi ]; platforms = lib.platforms.unix; }; })