diff --git a/modules/modules.nix b/modules/modules.nix index de626be2f..845881b52 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -92,6 +92,7 @@ let ./programs/chromium.nix ./programs/clock-rs.nix ./programs/cmus.nix + ./programs/codex.nix ./programs/command-not-found/command-not-found.nix ./programs/comodoro.nix ./programs/darcs.nix diff --git a/modules/programs/codex.nix b/modules/programs/codex.nix new file mode 100644 index 000000000..a8b8d6061 --- /dev/null +++ b/modules/programs/codex.nix @@ -0,0 +1,67 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit (lib) mkIf; + + cfg = config.programs.codex; + + settingsFormat = pkgs.formats.yaml { }; +in +{ + meta.maintainers = [ + lib.hm.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 { + inherit (settingsFormat) type; + description = '' + Configuration written to {file}`~/.codex/config.yaml`. + See for supported values. + ''; + default = { }; + defaultText = lib.literalExpression "{ }"; + example = lib.literalExpression '' + { + model = "gemma3:latest"; + provider = "ollama"; + 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 = mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + home.file = { + ".codex/config.yaml".source = settingsFormat.generate "codex-config" cfg.settings; + ".codex/AGENTS.md".text = cfg.custom-instructions; + }; + }; + +} diff --git a/tests/darwinScrublist.nix b/tests/darwinScrublist.nix index ee6527db5..952f7a0f2 100644 --- a/tests/darwinScrublist.nix +++ b/tests/darwinScrublist.nix @@ -29,6 +29,7 @@ let "cava" "clock-rs" "cmus" + "codex" "comodoro" "darcs" "delta" diff --git a/tests/default.nix b/tests/default.nix index 2ef53b55c..b1a644fd1 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -190,6 +190,7 @@ import nmtSrc { ./modules/programs/cava ./modules/programs/clock-rs ./modules/programs/cmus + ./modules/programs/codex ./modules/programs/comodoro ./modules/programs/darcs ./modules/programs/dircolors diff --git a/tests/modules/programs/codex/custom-instructions.md b/tests/modules/programs/codex/custom-instructions.md new file mode 100644 index 000000000..4edb15fb9 --- /dev/null +++ b/tests/modules/programs/codex/custom-instructions.md @@ -0,0 +1,2 @@ +- Always respond with emojis +- Only use git commands when explicitly requested diff --git a/tests/modules/programs/codex/custom-instructions.nix b/tests/modules/programs/codex/custom-instructions.nix new file mode 100644 index 000000000..149c489da --- /dev/null +++ b/tests/modules/programs/codex/custom-instructions.nix @@ -0,0 +1,14 @@ +{ + programs.codex = { + enable = true; + custom-instructions = '' + - Always respond with emojis + - Only use git commands when explicitly requested + ''; + }; + nmt.script = '' + assertFileExists home-files/.codex/AGENTS.md + assertFileContent home-files/.codex/AGENTS.md \ + ${./custom-instructions.md} + ''; +} diff --git a/tests/modules/programs/codex/default.nix b/tests/modules/programs/codex/default.nix new file mode 100644 index 000000000..4e26d2914 --- /dev/null +++ b/tests/modules/programs/codex/default.nix @@ -0,0 +1,4 @@ +{ + codex-settings = ./settings.nix; + codex-custom-instructions = ./custom-instructions.nix; +} diff --git a/tests/modules/programs/codex/settings.nix b/tests/modules/programs/codex/settings.nix new file mode 100644 index 000000000..23695230c --- /dev/null +++ b/tests/modules/programs/codex/settings.nix @@ -0,0 +1,21 @@ +{ + programs.codex = { + enable = true; + settings = { + model = "gemma3:latest"; + provider = "ollama"; + providers = { + ollama = { + name = "Ollama"; + baseURL = "http://localhost:11434/v1"; + envKey = "OLLAMA_API_KEY"; + }; + }; + }; + }; + nmt.script = '' + assertFileExists home-files/.codex/config.yaml + assertFileContent home-files/.codex/config.yaml \ + ${./settings.yml} + ''; +} diff --git a/tests/modules/programs/codex/settings.yml b/tests/modules/programs/codex/settings.yml new file mode 100644 index 000000000..be566143a --- /dev/null +++ b/tests/modules/programs/codex/settings.yml @@ -0,0 +1,7 @@ +model: gemma3:latest +provider: ollama +providers: + ollama: + baseURL: http://localhost:11434/v1 + envKey: OLLAMA_API_KEY + name: Ollama