mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
- Configuration file is now placed in XDG_CONFIG_HOME/codex/config.toml by default for versions >=0.2.0 when preferXdgDirectories is enabled. - Falls back to ~/.codex/config.yaml for versions <0.2.0 and to ~/.codex/config.toml when preferXdgDirectories is disabled - Sets CODEX_HOME environment variable to $XDG_CONFIG_HOME/codex when using XDG directories. - Updated tests to verify XDG directory behavior and environment variable presence.
90 lines
2.8 KiB
Nix
90 lines
2.8 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
inherit (lib) mkIf;
|
|
|
|
cfg = config.programs.codex;
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
yamlFormat = pkgs.formats.yaml { };
|
|
|
|
packageVersion = if cfg.package != null then lib.getVersion cfg.package else "0.2.0";
|
|
isTomlConfig = lib.versionAtLeast packageVersion "0.2.0";
|
|
settingsFormat = if isTomlConfig then tomlFormat else yamlFormat;
|
|
in
|
|
{
|
|
meta.maintainers = [
|
|
lib.maintainers.delafthi
|
|
];
|
|
|
|
options.programs.codex = {
|
|
enable = lib.mkEnableOption "Lightweight coding agent that runs in your terminal";
|
|
|
|
package = lib.mkPackageOption pkgs "codex" { nullable = true; };
|
|
|
|
settings = lib.mkOption {
|
|
# NOTE: `yaml` type supports null, using `nullOr` for backwards compatibility period
|
|
type = lib.types.nullOr tomlFormat.type;
|
|
description = ''
|
|
Configuration written to {file}`CODEX_HOME/config.toml` (0.2.0+)
|
|
or {file}`~/.codex/config.yaml` (<0.2.0). Per default {env}`CODEX_HOME`
|
|
defaults to ~/.codex.
|
|
See <https://github.com/openai/codex/blob/main/codex-rs/config.md> for supported values.
|
|
'';
|
|
default = { };
|
|
defaultText = lib.literalExpression "{ }";
|
|
example = lib.literalExpression ''
|
|
{
|
|
model = "gemma3:latest";
|
|
model_provider = "ollama";
|
|
model_providers = {
|
|
ollama = {
|
|
name = "Ollama";
|
|
baseURL = "http://localhost:11434/v1";
|
|
envKey = "OLLAMA_API_KEY";
|
|
};
|
|
};
|
|
}
|
|
'';
|
|
};
|
|
custom-instructions = lib.mkOption {
|
|
type = lib.types.lines;
|
|
description = "Define custom guidance for the agents; this value is written to {file}~/.codex/AGENTS.md";
|
|
default = "";
|
|
example = lib.literalExpression ''
|
|
'''
|
|
- Always respond with emojis
|
|
- Only use git commands when explicitly requested
|
|
'''
|
|
'';
|
|
};
|
|
};
|
|
|
|
config =
|
|
let
|
|
useXdgDirectories = (config.home.preferXdgDirectories && isTomlConfig);
|
|
xdgConfigHome = lib.removePrefix config.home.homeDirectory config.xdg.configHome;
|
|
configDir = if useXdgDirectories then "${xdgConfigHome}/codex" else ".codex";
|
|
configFileName = if isTomlConfig then "config.toml" else "config.yaml";
|
|
in
|
|
mkIf cfg.enable {
|
|
home = {
|
|
packages = mkIf (cfg.package != null) [ cfg.package ];
|
|
file = {
|
|
"${configDir}/${configFileName}" = lib.mkIf (cfg.settings != { }) {
|
|
source = settingsFormat.generate "codex-config" cfg.settings;
|
|
};
|
|
"${configDir}/AGENTS.md" = lib.mkIf (cfg.custom-instructions != "") {
|
|
text = cfg.custom-instructions;
|
|
};
|
|
};
|
|
sessionVariables = mkIf useXdgDirectories {
|
|
CODEX_HOME = "${config.xdg.configHome}/codex";
|
|
};
|
|
};
|
|
};
|
|
}
|