NixOS 模块说明
这个 flake 导出了 nixosModules.default 和 nixosModules.codex-quota-monitor。
最小示例
{
inputs.codexQuotaMonitor.url = "github:<owner>/codex-quota-monitor";
outputs = inputs@{ self, nixpkgs, codexQuotaMonitor, ... }: {
nixosConfigurations.my-host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
codexQuotaMonitor.nixosModules.default
({ ... }: {
services.codexQuotaMonitor = {
enable = true;
installCli = true;
managementBaseUrl = "http://127.0.0.1:8317";
managementKeyFile = "/path/to/management-key";
gatewayHealthUrl = "http://127.0.0.1:8317/healthz";
authDir = "/path/to/auth-files";
# 可选,默认关闭。开启后会把 live_plan_* metadata 写回 CPA auth files,
# 供路由器使用 fresh plan state。
# authLivePlanSync.enable = true;
};
})
];
};
};
}
关键选项
services.codexQuotaMonitor.enableservices.codexQuotaMonitor.packageservices.codexQuotaMonitor.installCliservices.codexQuotaMonitor.userservices.codexQuotaMonitor.groupservices.codexQuotaMonitor.listenAddressservices.codexQuotaMonitor.allowedHostsservices.codexQuotaMonitor.portservices.codexQuotaMonitor.demoservices.codexQuotaMonitor.managementBaseUrlservices.codexQuotaMonitor.managementKeyFileservices.codexQuotaMonitor.manualQuotaRefreshAuthservices.codexQuotaMonitor.allowBrowserKeyStorageservices.codexQuotaMonitor.gatewayHealthUrl(http(s)或fileJSON URL)services.codexQuotaMonitor.authDirservices.codexQuotaMonitor.authLivePlanSync.enableservices.codexQuotaMonitor.refreshSecondsservices.codexQuotaMonitor.usageRefreshSecondsservices.codexQuotaMonitor.directQuotaRecoverySecondsservices.codexQuotaMonitor.timeoutSecondsservices.codexQuotaMonitor.weeklyToFiveHourMultiplierservices.codexQuotaMonitor.stateDbservices.codexQuotaMonitor.clientLabelsFileservices.codexQuotaMonitor.usageQueueRawEventLogservices.codexQuotaMonitor.historyWriteSecondsservices.codexQuotaMonitor.historyRetentionDaysservices.codexQuotaMonitor.benchmarkSummaryservices.codexQuotaMonitor.displayTimezoneservices.codexQuotaMonitor.displayLocaleservices.codexQuotaMonitor.uiFontFamilyservices.codexQuotaMonitor.monoFontFamilyservices.codexQuotaMonitor.alertFiveHourMinPlusservices.codexQuotaMonitor.alertWeeklyMinPlusservices.codexQuotaMonitor.alertRoutableAccountsMinservices.codexQuotaMonitor.openFirewallservices.codexQuotaMonitor.logLevelservices.codexQuotaMonitor.logFormatservices.codexQuotaMonitor.accessLog
默认值
- 监听地址:
127.0.0.1 - 允许的浏览器 host/origin:默认只放行 loopback;需要额外放行时设置
allowedHosts - 端口:
4515 - Demo 模式:默认关闭;只在需要用内置示例数据做零 secret 预览时设
demo = true - Management gateway:
http://127.0.0.1:8317 - Management key file:默认不配置;裸 CPA 要把
managementKeyFile指向包含 CPAremote-management.secret-key同一明文值的运行时 secret 路径;只有managementBaseUrl指向本地自动注入 key 的 proxy 时才省略 - 手动 quota refresh 鉴权:默认
ui-token;浏览器使用页面内刷新 token,不需要 CPA management key。只有需要旧行为时才设置manualQuotaRefreshAuth = "management-key",可信本地部署才设置"none" - 浏览器保存 key:默认关闭;只对旧的
manualQuotaRefreshAuth = "management-key"部署生效,且只应在接受 localStorage 持久化风险时启用 - Auth live plan sync:默认关闭。设置
authLivePlanSync.enable = true后,module 会新增独立 timer/oneshot,把 direct Codex plan sample 作为live_plan_*metadata 写回 auth files。它要求设置authDir,并且只给同步 unit 该目录写权限;dashboard service 对 auth files 仍保持只读。 同步 runner 会拒绝替换无法保留原 owner/group 的 auth file;实际部署时应让该 unit 以 auth file owner 运行,或用 systemd override 明确调整。 - 防火墙:默认不放行
- 交互 CLI:默认不装进系统 profile;如果用户需要在 host shell 里直接运行
codex-quota-monitor、cqm或codex-quota-benchmark,设置installCli = true - service 账号:
codex-quota-monitor - Usage refresh interval:默认
null,CLI 会跟随refreshSeconds。如果想让 CPA/v0/management/usage比普通 health/auth/config 刷新更慢,设置usageRefreshSeconds - weekly-to-5h multiplier:默认
6.0;设weeklyToFiveHourMultiplier = null可以关闭 cap。账号 weekly 已耗尽时仍会从总5h容量里移除 - SQLite history DB:
/var/lib/codex-quota-monitor/history.sqlite3;设stateDb = null可以关闭 Trends、Audit、Stats 时间序列 workbench 和原生历史备份 - Usage queue raw event log:默认关闭。把
usageQueueRawEventLog指向 sanitized CLIProxyAPI v7 usage queue collector JSONL,例如/var/lib/cli-proxy-api/usage-queue/events.jsonl后,Stats workbench 会把新请求详情导入 SQLite history。 - Client labels file:默认关闭。把
clientLabelsFile指到运行时 JSON 文件后, Stats 可用client分组;module 只传路径,真实 CPA API name 应放在/run/secrets、/etc或其它受保护的运行时文件里,不要 inline 到 Nix 文本。 - 历史写入间隔:
60秒 - 历史保留期:
30天 - Benchmark 摘要:默认关闭;把
benchmarkSummary指到codex-quota-benchmark的summary.json后会显示在 Trends 里 - 显示时区:默认
local;需要固定 reset 时间时可设displayTimezone = "UTC";、displayTimezone = "Asia/Shanghai";或其它 IANA 时区 - 显示语言:默认
auto;dashboard 会跟随浏览器 locale,目前支持en和zh-CN。需要服务级固定默认值时可设displayLocale = "en";或displayLocale = "zh-CN"; - UI 字体:默认使用中性的系统 UI 字体栈。需要 operator 级默认值时,把
uiFontFamily设成 CSSfont-family列表 - Mono 字体:默认使用中性的系统等宽字体栈。访问端已安装 Maple 时,可以设
monoFontFamily = "\"Maple Mono NF CN\", ui-monospace, monospace"; - 阈值告警:默认关闭;设置
alert*选项后会通过/api/v1/alerts暴露 - 日志:
logLevel = "INFO"、logFormat = "text"、accessLog = true。日志写到 stderr 并交给 journald;需要每行一个 JSON object 时设logFormat = "json"。
Dashboard 里的浏览器本地偏好会覆盖这些服务默认值,但只影响当前浏览器。locale、
timezone 和字体偏好彼此独立:locale 控制 UI 语言和浏览器侧日期/数字格式,
timezone 只控制 reset 时间显示,字体只选择 CSS font-family 栈。项目不内置
字体文件;字体名只有在渲染页面的设备已经安装该字体时才会命中。
如果你要让手机或小屏浏览器通过局域网访问,把 listenAddress 设成
0.0.0.0,把浏览器访问用的域名或 IP 加进 allowedHosts,并把
openFirewall 设成 true。这只会让 dashboard 可达并放行预期的 Host /
Origin,不会鉴权访问者。LAN 或公网访问仍要用 firewall 规则和带鉴权的
reverse proxy 或 access layer 保护。