fix: nb codex-cli wrapper

This commit is contained in:
2025-10-08 22:05:19 +02:00
parent af60555eea
commit 0b6549a359

View File

@@ -14,10 +14,30 @@ in {
python314 # useful for codex model use python314 # useful for codex model use
jq # useful for JSON processing jq # useful for JSON processing
(pkgs.writeShellScriptBin "codex" '' (pkgs.writeShellScriptBin "codex" ''
#!/usr/bin/env bash #!${pkgs.bash}/bin/bash
export TMPDIR="''${TMPDIR:-$HOME/.cache/codex-tmp}" set -euo pipefail
export XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-$HOME/.cache/xdg-runtime}"
exec ${npmPrefix}/bin/codex "$@" # Required dirs
mkdir -p "$HOME/.cache/codex-tmp" "$HOME/.cache/xdg-runtime" "$HOME/.config" "$HOME/.cache" "$HOME/.local/share"
chmod 700 "$HOME/.cache/codex-tmp" "$HOME/.cache/xdg-runtime" "$HOME/.config" "$HOME/.local/share"
# Pass through cert vars if present (avoids TLS issues)
EXTRA_ENV=()
[ -n "''${SSL_CERT_FILE-}" ] && EXTRA_ENV+=(SSL_CERT_FILE="$SSL_CERT_FILE")
[ -n "''${NIX_SSL_CERT_FILE-}" ] && EXTRA_ENV+=(NIX_SSL_CERT_FILE="$NIX_SSL_CERT_FILE")
exec env -i \
HOME="$HOME" \
USER="''${USER:-$LOGNAME}" \
SHELL="''${SHELL:-${pkgs.bash}/bin/bash}" \
PATH="/run/current-system/sw/bin:/usr/bin:/bin" \
XDG_RUNTIME_DIR="$HOME/.cache/xdg-runtime" \
TMPDIR="$HOME/.cache/codex-tmp" \
XDG_CONFIG_HOME="$HOME/.config" \
XDG_CACHE_HOME="$HOME/.cache" \
XDG_DATA_HOME="$HOME/.local/share" \
"''${EXTRA_ENV[@]}" \
${npmPrefix}/bin/codex "$@"
'') '')
]; ];
@@ -40,11 +60,6 @@ in {
NPM_CONFIG_PREFIX = npmPrefix; NPM_CONFIG_PREFIX = npmPrefix;
}; };
home.activation.ensureCodexDirs = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
install -d -m 700 "${config.home.homeDirectory}/.cache/codex-tmp"
install -d -m 700 "${config.home.homeDirectory}/.cache/xdg-runtime"
'';
# Auto-install @openai/codex if it's not already there # Auto-install @openai/codex if it's not already there
# (idempotent on each `home-manager switch`) # (idempotent on each `home-manager switch`)
home.activation.installCodexCli = lib.hm.dag.entryAfter [ "writeBoundary" ] '' home.activation.installCodexCli = lib.hm.dag.entryAfter [ "writeBoundary" ] ''